Download presentation
Presentation is loading. Please wait.
1
Mediator Design Pattern (Behavioral)
-Seema Joshi
2
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
3
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
4
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
5
Example- Problem 03/04/03 CS590L Mediator Pattern
6
Example -Solution 03/04/03 CS590L Mediator Pattern
7
Example -Sequence Diagram
03/04/03 CS590L Mediator Pattern
8
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
9
Example -Structure 03/04/03 CS590L Mediator Pattern
10
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
11
General Structure 03/04/03 CS590L Mediator Pattern
12
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
13
Another Example 03/04/03 CS590L Mediator Pattern
14
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
15
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
16
Related Patterns Facade Observer 03/04/03 CS590L Mediator Pattern
17
?????????????? You may have questions, if you didn’t pay attention during the presentation. 03/04/03 CS590L Mediator Pattern
18
References Design Patterns: Elements of Reuseable Object-Oriented Software by E. Gamma, R. Helm, R. Johnson and J. Vlissides, Addison-Wesley, ISBN: , Copyright 1995. 03/04/03 CS590L Mediator Pattern
19
Thank You 03/04/03 CS590L Mediator Pattern
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.