Home arrow PHP arrow Introducing Mediator Classes in PHP 5

Introducing Mediator Classes in PHP 5

The mediator design pattern can help you achieve and maintain synchronization between a group of PHP classes. In this first of a two-part series, you'll be introduced to the mediator pattern, how it functions, and how it can help you with your application development.

  1. Introducing Mediator Classes in PHP 5
  2. Creating a simple mediator class
  3. Building a pair of data file handling classes
  4. Building a practical example
By: Alejandro Gervasio
Rating: starstarstarstarstar / 5
March 13, 2007

print this article




As you'll possibly agree with me, at some point in your productive life as PHP developer, you've had to build web applications comprised of different, highly independent modules, which naturally perform well-differentiated tasks. Besides, it's normal to see that these modules very often establish a carefully planned interaction with each other, by means of a centralized mechanism, to stay in synchronization with the rest of the application.

Database interfaces and data validation systems, among other applications, are clear examples of using a unique, centralized programming module to keep all the different components that integrate a PHP application synchronized. You should be quite familiar with this concept.

The previous schema of interaction between the diverse modules of a given application seems to be pretty straightforward to implement during the development period; however, it should be admitted that this model isn't too easy to apply, particularly when it comes to using a set of predefined PHP classes.

The creation of a specific class, which has to be capable of keeping the interaction of other classes centralized (and synchronized) sounds hard to achieve, at least without using the benefits offered by pattern-based programming. So what's the point in utilizing this approach, after all?

Well, in this case, the synchronization between a group of PHP classes can be made by implementing a useful pattern widely known as "mediator." In short, when the mediator pattern is applied, there's a single class that implements the logic required to keep all the other classes completely synchronized with each other. This means that not only will all the modifications introduced by one class be reflected in the others, but that those changes will be performed via the interface of the mediator class.

Of course, it's quite possible that you find the above definition rather hard to grasp, therefore in this two-part series, I'm going to show you how a mediator class can be defined, and logically how it can be put to work as well, by employing numerous instructive examples.

So, are you ready to learn more about how to implement this handy design pattern with PHP 5? Okay, let's get started now!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: