Applied Design Patterns with Java

Behavioral :: Mediator (273) {C ch 20}


Collaborations

Consequences

Mediator has the following benefits and liabilities:

  1. 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.
  2. It decouples colleagues. A Mediator promotes loose coupling between colleagues. Colleague and Mediator classes can be varied and reused independently.
  3. 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.
  4. 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.
  5. 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