2015年3月17日星期二

NetTuts.com: Design Patterns: The Command Pattern


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.


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

没有评论:

发表评论