SOFTWARE ARCHITECTURE AND DESIGN
PATTERNS
UNIT-V
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.
MEDIATOR
Sample code
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.
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
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
• 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
• 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.

Mediator.pptx

  • 1.
    SOFTWARE ARCHITECTURE ANDDESIGN PATTERNS UNIT-V
  • 2.
    Mediator(Bheavioural) Intent: Define anobject 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.
  • 3.
  • 8.
  • 11.
    Applicability: Use theMediator 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 sendand 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
  • 15.
    Related Patterns • Facadediffers 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: Thefollowing 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.