Mediator Pattern CSE776 Design Pattern. Talks Yunding Li Tianhang Zhang Cunyang Shui 1 Motivation • ln order to have a good object oriented design we have to create lots of classes interacting one with each other. If certain principles are not applied the final framework will end in a total mess where each object relies on many other objects in order to run. In order to avoid tight coupled frameworks, we need a mechanism to facilitate the interaction between objects in a manner in that objects are not aware of the existence of other objects. 2 Motivation • Programming scales 3 Motivation 4 Motivation 5 Mediator • FontDialogBox: Structure.Related Patterns.Implementation Will Zhang 7 Structure Mediator (DialogDirector) -defines an interface for communicating with Colleague objects. ConcreteMediator(FontDialogDirector) -implements cooperative behavior by coordinating Colleague objects. -knows and maintains its colleagues. Colleague classes (ListBox, EntryField) -each Colleague class knows its Mediator object. -each colleague communicates with its mediator whenever it would have otherwise communicated with another colleague. 8 Structure 9 Consequences 1. Decouples colleagues. Mediator promotes loose coupling among colleagues. 2. Simplifies object protocols. Mediator replaces many-to-many interactions with one-to-many interactions. 3. Integrate objects to work together as a system. 4. Centralizes control. The Mediator pattern trades complexity of interaction for complexity in the mediator. Because a mediator encapsulate protocols, it can become more complex than any individual colleague. This can make the mediator itself a monolith that’s hard to maintain. 10 Related Patterns Facade Mediator Adapter Observer 11 Related Patterns – Mediator vs. Facade Client Facade Med iator Mediator Facade 12 Related Patterns – Mediator vs. Adaptor Incompatibility 13 Related Patterns – Mediator vs. Observer • Observers send out messages unselectively, while Mediator can target related receivers. • Easier to make reusable Observers and Subjects than to make reusable Mediators. • On the other hand, Mediator can leverage Observer for dynamically registering colleagues and communicating with them. 14 Implementation • Colleague-Mediator communication 15 Implementation • When communicating with the mediator, a colleague passes itself as an argument, allowing the mediator to identify the sender. 16 Implementation • sending notifications to the mediator whenever they change state. The mediator responds by propagating the effects of the change to other colleagues. 17 Control Tower Example 18
© Copyright 2026 Paperzz