Mediator Pattern
Design Patterns
Motivating Example
When you have many objects of a similar type that need to
communicate with each other
The communication between objects is complex
Definition
Define an object that encapsulates how a set of objects interact.
Mediator promotes loose coupling by keeping objects from
referring to each other explicitly, and it lets you vary their
interaction independently.
Gamma et al., 1995
Components
Colleagues
Individual components that need to communicate with each other
Implement the same base type (abstract class or interface)
Have knowledge of the Mediator component
Components
Mediator
The centralized component that managed communication between the
colleague components
Implements an abstraction that is used by the Colleague components
Advantages & Disadvantages
Advantages:
Hides all coordination between colleagues
Decoupled colleagues
Mediator’s one-to-many relationship with colleagues is
preferred to colleagues relating in a many-to-many fashion
Disadvantages:
The Mediator can become very large and very complicated as
more colleagues are handled
Summary
Mediator provides a centralized location for communication
between many instances of like classes
Enhances decoupling
For more in-depth online developer training visit
on-demand content from authors you trust