Applied Design Patterns with Java
Behavioral :: Mediator (273) {C ch 20}
Collaborations
- Colleagues send and receive requests from a Mediator
object. The Mediator implements the cooperative behavior by routing requests between the appropriate
colleague(s).
Consequences
Mediator
has the following benefits and liabilities:
- It limits subclassing. A
Mediator
localizes behavior that otherwise would be distributed among several objects. Changing this behavior requires subclassing
Mediator
only; a Colleague class can be reused as is.
- It decouples colleagues. A Mediator promotes loose coupling between colleagues. Colleague and Mediator
classes can be varied and reused independently.
- It simplifies object protocols. A Mediator replaces many-to-many interactions with one-to-many interactions between the
Mediator
and its colleagues. One-to-many relationships are easier to understand, maintain, and extend.
- It abstracts how objects cooperate. Making mediation an independent concept and encapsulating it in an object allows a focus
on how objects interact apart from their individual behavior. That can help clarify how objects interact in a system.
- It centralizes control.
The Mediator
pattern trades complexity of interaction for complexity in the Mediator. Because a Mediator encapsulates protocols, it can become more complex than any individual colleague.
This can make the Mediator itself a monolith that's hard to maintain.
Catalog Behavioral Prev Next