Mediator A Behavioral Design Pattern for the New
Mediator A Behavioral Design Pattern for the New Millennium Cory Nugent
Designing for OOP l Goals of Object Oriented Design Distribute behavior among different objects. l Encourage code reuse l Facilitate communication between objects l
What’s the Problem? l Communication between objects becomes too complicated. l Changing system behavior becomes too difficult. l No central access points are available.
DAS MEDIATØR! l. A class that controls interactions of a group of other objects. l Promotes loose coupling (Objects don’t explicitly reference each other). l Objects need only know about their mediator. l Provides a centralized behavior management point.
The Good l Changing system behavior means subclassing the mediator. l Mediator and Colleague classes are independent of each other. l Mediator-Colleague relationship is one to many; Colleague-Colleague relationship is many to many. l Object interaction becomes easy to understand.
The Bad l All object interactions are bundled into the mediator. l The mediator class can be complex and hard to maintain.
How it all works Diagram courtesy of Gopalan Suresh Raj
The Mediator l Defines an interface for communicating with colleague classes. l Concrete l Mediator Coordinates colleague objects
How it all works Diagram courtesy of Gopalan Suresh Raj
The Colleagues l Colleague l Defines an interface for communicating with mediator class. l Concrete Colleagues Each colleague knows its mediator l Each colleague communicates with its mediator when it would otherwise communicate with its colleague. l
How it all works Diagram courtesy of Gopalan Suresh Raj
There is no more presentation l Thank you, come again.
- Slides: 12