DevShed’s Alejandro Gervasio has posted a tutorial titled Introduction to Creating Command Objects with PHP 5. In it he explores the Command design pattern. Here’s let’s sneak a quick peek.
In the command pattern, one object encloses all the programming logic required for executing a specific method into another one. Sounds pretty simple, doesn’t it?
In this case, the object responsible for encapsulating the logic of a method into another is called the commanded one, while the object that calls the method in question is the commander. Most of the time, the commander exposes an “execute()” method or something similar, which is only responsible for invoking a method of the mentioned commanded. Naturally, this group of buzzwords that I have used will be much easier to grasp when you take a look at the introductory examples that you’ll learn over the course of this series.
From there he takes his readers on a 5 page journey through the command patterns. The tutorial is liberally sprinkled with source code examples to explain the sometimes confusing text.
This is not really a beginners tutorial. It requires PHP 5 and a firm grounding in object oriented design. However, if you’ve been at this a while and are looking to stretch in new directions, this tutorial is worth your time.
=C=


Comments (Login to leave comments)
Also, the tutorial presents a very simple implementation of the Command pattern which left me wondering "what's the point?" This was quickly dispelled by further research into the pattern. The Wikipedia article on this pattern has a great list of uses: http://en.wikipedia.org/wiki/Command_pattern