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

Design Patterns: The Command Pattern
Mar 17, 2015 @ 17:42:22

NetTuts.com continues their series covering the basics of design patterns (in PHP) with a new article about the Command design pattern. This pattern is particularly useful for executing self-contained "commands" without other interaction.

In this article, we will be going through the command design pattern. As the name says, in this pattern we will be dealing with executing various commands. [...] Basically a pattern has numerous elements involved, which are as below. In the next section, we will be exploring each element with a code example. I will be taking the example of radio actions—very basic actions would be turning the radio on or off. So let's dive into each element.

Using the illustration of the radio, they go through the creation of the classes for the controls (on/off) and the two matching commands. The invoker is then told to execute the "turn off" command on the radio control object passed in. This sounds a little confusing but the code included in the article makes it clear how this implementation of the command is structured.

tagged: designpattern tutorial series command pattern radio example

Link: http://code.tutsplus.com/tutorials/design-patterns-the-command-pattern--cms-22942

Trending Topics: