Mediator Pattern
Overview
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.
Participants
- defines an interface for communicating with Colleague objects.
- implements cooperative behavior by coordinating Colleague objects.
- knows and maintains its colleagues.
- each Colleague class knows its Mediator object.
- each colleague communicates with its mediator whenever it would have otherwise
communicated with another colleague.
- defines the interface for Colleague objects.
Parameters
- name of the method for notification. The method handles changes of particular
colleagues.
-
when selected, will create special JavaDoc links in the code between pattern participants, describing
their relationships.
Applicability
Use the Mediator pattern when
- a set of objects communicate in well-defined but complex ways. The resulting interdependencies
are unstructured and difficult to understand.
- reusing an object is difficult because it refers to and communicates with many other
objects.
- a behavior that is distributed between several classes should be customizable
without a lot of subclassing.