12.1. Problem and Solution

When objects start becoming too tightly coupled, the benefits of Object Oriented Programming start to disappear. While still working with objects, the style begins to shift towards procedural. The code base starts to become monolithic and cumbersome. Before the solutions can be applied, this particular problem needs to be investigated further. It is important to understand the underlying causes. The same problems that the Mediator Design Pattern solves can slowly creep into other instances of the code.

When objects that are not specifically designed to deal with each other start realizing relationships, a problem has begun. Now, there are times when objects are created to work with child objects or collections. This is a perfectly fine architectural choice. However, when interchangeable objects or objects not based on the same framework start to have interdependencies, problems develop — usually when an object is updated or its interface changes or when an update needs to be applied to an object. It may be tempting to add a new method to update similar objects with the same information. However, by adding this method, the object is gaining an understanding of and relationship with another object that it need not be coupled to. The most immediate consequence comes from the other object's public methods changing. Now, not only is the other object being modified, but this unrelated object's method needs to be updated.

Objects based on the Mediator Design ...

Get Professional PHP Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.