Mediator Pattern
Explore the mediator pattern to understand how it centralizes communication among objects, reducing direct dependencies and lowering complexity in software. This lesson guides you through the pattern's concepts, benefits, and implementation using real-world Java examples like an air traffic control system to enhance your ability to design maintainable and flexible software architectures.
We'll cover the following...
What is it ?
A mediator is defined as a person who makes people involved in a conflict come to an agreement. The pattern definition however, isn't violent and says the pattern is applied to encapsulate or centralize the interactions amongst a number of objects. Object orientated design may result in behavior being distributed among several classes and lead to too many connections among objects. The encapsulation keeps the objects from referring to each other directly and the objects don't hold references to each other anymore.
Formally, the pattern is defined as encouraging loose coupling among interacting objects by encapsulating their interactions in a mediator object, thus avoiding the need for individual objects to refer to each other directly and allowing to vary object interactions independently.
A mediator controls and coordinates the behavior for a group of objects. The objects only communicate with the mediator or the director and don't know of the other objects.
The mediator pattern should be applied when there are many objects communicating in a well-structured but complex manner resulting in ...