HomePHP Object Interaction and Mediator Classes in PHP 5
Object Interaction and Mediator Classes in PHP 5
Are you looking for an approachable guide on how to use the mediator design pattern in PHP 5? If you answered "yes," then you should take a look at this group of articles. Welcome to the final part of the series that began with “Introducing Mediator Classes in PHP 5.” This series takes you through building mediator classes with PHP, and shows you how to use this useful pattern with copious code samples.
If you already went through the first tutorial of the series, then quite possibly the mediator pattern will be quite familiar to you. However, if it doesn't ring any bells, let me offer you a quick introduction to how it works. This will let you can grasp more easily the purpose of the hands-on examples that I plan to include in this final article of the series.
Essentially, when the mediator pattern is implemented in the context of a given PHP application, there's a class (the mediator) which behaves as a centralized mechanism that maintains a complete synchronization between two or more additional classes. These classes are structured in such a way that all the tasks that they perform are handled via the respective mediator.
Logically, the rather confusing character of the previous definition implies that the topic must be complemented with a decent number of practical examples. These will hopefully serve to help you understand the logic that drives the mediator pattern more easily.
Therefore, keeping in mind the strong educational sense that the subject really deserves, in the first article of the series I built a mediator class which was provided with the ability to keep a couple of data file handling classes entirely synchronized. This meant that when one class changed the case of the data it handled, the other one also reflected this modification via the mediator. Quite good, right?
Okay, at this stage I believe that implementing the mediator pattern with PHP 5 should be a pretty painless process to you, but if the examples that I showed you in the first article weren't enough to help you completely grasp this pattern, over the course of this last tutorial I'm going to expand the original mediator class that you learned previously. The expansion will make it capable of maintaining three classes in perfect synchronization.
Well, with the preliminaries out of our way, let's learn more examples of how to apply the mediator pattern with PHP 5. Let's go!