Mediator Design Pattern (Behavioral) -Seema Joshi
Intent 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. 03/04/03 CS590L Mediator Pattern
Motivation Object oriented design encourages the distribution of behavior among objects. Partitioning a system into many objects enhances reusability. Many connections between objects in an object structure. -Lots of interconnections increases interdependency. -Moreover it can be difficult to change the systems' behavior in any significant way, since behavior is distributed among many objects. 03/04/03 CS590L Mediator Pattern
Applicability When one or more objects must interact with several different objects. When simple object need to communicate in complex ways. When you want to reuse an object that frequently interacts with other objects. 03/04/03 CS590L Mediator Pattern
Example- Problem 03/04/03 CS590L Mediator Pattern
Example -Solution 03/04/03 CS590L Mediator Pattern
Example -Sequence Diagram 03/04/03 CS590L Mediator Pattern
Example -Steps The list box tells its director that it’s changed. The director gets the selection from the list box. The director passes the selection to the entry field. Director takes action. 03/04/03 CS590L Mediator Pattern
Example -Structure 03/04/03 CS590L Mediator Pattern
Example -Relationship DialogDirector is an abstract class that defines the overall behavior of a dialog. Clients call ShowDialog() CreateWidgets() –abstract operation for creating widgets. 03/04/03 CS590L Mediator Pattern
General Structure 03/04/03 CS590L Mediator Pattern
Participants Mediator ConcreteMediator Colleague classes -defines an interface for communicating with Colleague objects. ConcreteMediator -implements cooperative behavior by coordinating Colleague objects. -knows and maintains its colleagues. Colleague classes -each Colleague class knows its Mediator object. -each colleague communicates with its mediator whenever it would have otherwise communicated with another colleague. 03/04/03 CS590L Mediator Pattern
Another Example 03/04/03 CS590L Mediator Pattern
Good Points about the Mediator Centralized control Less chance of miscommunication. Simplifies object protocols Replaces many-to-many interactions with one-to-many interactions between mediator and colleagues, thus simple to understand, maintain and extend. Abstracts how objects cooperate Splitting up the system in this way creates a better understanding of the objects in the system, how they interact and how they are structured . Loose coupling between colleagues promotes Reusability Basically, it proliferates interconnections to help eventually reduce it. 03/04/03 CS590L Mediator Pattern
Bad Points about the Mediator Overloading the Mediator There is the potential for numerous subclasses of the Mediator and these in turn could require subclasses of those Mediator subclasses. It's just a horrible cycle from this point on. Hindrance If there are a relatively small group of objects, it may waste less time if they are able to speak to each other directly rather than through a Mediator. 03/04/03 CS590L Mediator Pattern
Related Patterns Facade Observer 03/04/03 CS590L Mediator Pattern
?????????????? You may have questions, if you didn’t pay attention during the presentation. 03/04/03 CS590L Mediator Pattern
References Design Patterns: Elements of Reuseable Object-Oriented Software by E. Gamma, R. Helm, R. Johnson and J. Vlissides, Addison-Wesley, ISBN: 0-201-63361-2, Copyright 1995. http://sern.ucalgary.ca/courses/SENG/443/W02/assignments/Mediator/ 03/04/03 CS590L Mediator Pattern
Thank You 03/04/03 CS590L Mediator Pattern