2. Mediator(Bheavioural)
Intent: Define an object that encapsulates how a
set o f objects interact. Mediator promotes
loose coupling by keeping objects from
referring to each other explicitly, and it lets
you vary their interaction independently.
11. 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's distributed between several
classes should be customizable without a lot of
sub classing.
12. Collaborations
• Colleagues send and receive requests from a Mediator
object. The mediator implements the cooperative
behavior by routing requests between the appropriate
colleague
Consequences: The Mediator pattern has the following
benefits and drawbacks:
• It limits subclassing
• It decouples colleagues
• It simplifies object protocols
13.
14.
15. Related Patterns
• Facade differs from Mediator in that it
abstracts a subsystem of objects to provide a
more convenient interface
• Colleagues can communicate with the
mediator using the Observer pattern
16. • Mediator – defines the interface for communication
between Colleague objects
• ConcreteMediator – implements
the Mediator interface and coordinates communication
between Colleague objects. It is aware of all of the
Colleagues and their purposes with regards to inter-
communication.
• Colleague – defines the interface for communication
with other Colleagues through its Mediator
• ConcreteColleague – implements
the Colleague interface and communicates with other
Colleagues through its Mediator
17. • Implementation: The following implementation issues are relevant to the
Mediator pattern:
Omitting the abstract Mediator class. There's
no need to define an abstract Mediator class
when colleagues work with only one mediator.
The abstract coupling that the Mediator class
provides lets colleagues work with different
Mediator subclasses, and vice versa.