Mediator pattern
Intent
● Define an object that encapsulates how a set of
objects interact.
● Design an intermediary to decouple many
peers.
● Promote the many-to-many relationships
between interacting peers
Problem
● dependencies between the potentially reusable
pieces demonstrates the "spaghetti code"
phenomenon.
Motivation
● By consolidating all interaction in a single class,
we can regain elegance and reusability.
UML
Examples
Pros & Cons
Pros:
● Decouples colleagues, which facilitates independent
variations of the colleague and mediator classes.
● Simplifies protocol by replacing many-to-many interaction
with one-to-one interaction
Cons:
● Reducing the complexity of Colleagues increases
the complexity of the Mediator itself.
Related patterns
● Observer: the Mediator class may be
implemented using an Observer
● Facade: is similar to a Mediator, but with one-
way communication from the Facade to its
subsystem classes..
Mediator

Mediator

  • 1.
  • 2.
    Intent ● Define anobject that encapsulates how a set of objects interact. ● Design an intermediary to decouple many peers. ● Promote the many-to-many relationships between interacting peers
  • 3.
    Problem ● dependencies betweenthe potentially reusable pieces demonstrates the "spaghetti code" phenomenon.
  • 4.
    Motivation ● By consolidatingall interaction in a single class, we can regain elegance and reusability.
  • 5.
  • 6.
  • 8.
    Pros & Cons Pros: ●Decouples colleagues, which facilitates independent variations of the colleague and mediator classes. ● Simplifies protocol by replacing many-to-many interaction with one-to-one interaction Cons: ● Reducing the complexity of Colleagues increases the complexity of the Mediator itself.
  • 9.
    Related patterns ● Observer:the Mediator class may be implemented using an Observer ● Facade: is similar to a Mediator, but with one- way communication from the Facade to its subsystem classes..