Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

phpPatterns.com:
The Command Pattern
Jan 12, 2004 @ 13:33:16

phpPatterns.com has a new pattern posted this morning - the command pattern - one that can help you work with the "actions" in your web application and handle them simply no matter what kind of request.

The Command Pattern is about wrapping a request in an object. It turns up frequently in web application frameworks, e.g. form processing where the Command Pattern is used to handle user "actions". [...] The Gang of Four description of the Command Pattern's intent is "Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.". An alternative way to think about the Command Pattern, from the perspective of PHP (as a language that supports both procedural and object oriented paradigms) might be "To allow multiple implementations of the same function name, each implementation being wrapped in it's own class".

Basically, it allows you to, based on the type of action made by the user, create functions that abstract the action from the actual code doing the work. This can be quite handy for larger web applications, especially those with a lot of user input.
tagged:

Link:


Trending Topics: