HomePHP Using Self-Saving Objects with Command Objects in PHP 5
Using Self-Saving Objects with Command Objects in PHP 5
If you were looking for an approachable guide on how to create and use command objects with PHP 5, then look no further, because your search is over. Welcome to the final part of the series “Creating command objects with PHP 5.” Comprised of three comprehensive tutorials, this series walks you through the basics of how to apply the command pattern in PHP, and it accompanies its corresponding theory with numerous code samples.
Certainly, one of the things that you’ll surely recall from the preceding article is the fact that implementing the command pattern with PHP is a quite straightforward process which can be carried out with minor problems. As you learned before, the procedure is only limited to defining a specific class, dubbed “commanded,” which will expose a method capable of encapsulating all the logic required for execution in another object. Lastly, this second object involved in the relationship is called a “commander,” and it will take care of invoking the mentioned method inside of its own scope. That's fairly understandable, right?
Of course, one of the best courses of action to take when it comes to explaining the logic that stands behind the command pattern is to develop some concrete examples. In this way you can see how these objects interact with each other, as well as the neat functionality of this pattern.
Now, and focusing my attention specifically on the topics that I plan to discuss in this final part of the series, I’m going to extend the creation and use of command objects to use the pattern in a more helpful fashion. Essentially, I’m going to explain how to utilize command classes for defining and handling self-saving objects, that is objects capable of storing a copy of themselves on a database, text file, etc.
By doing so, I'll give you a much clearer idea of how the command pattern can be used in real-world applications, and at the same time you’ll expand your existing background in using design patterns with PHP 5 as well.
With the preliminaries out of our way, it’s time to find out together how to use commanders in the creation of self-saving objects. The experience will be really educational, so let’s get started!