The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.

Slides:



Advertisements
Similar presentations
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Advertisements

UMBC Some Additional Patterns CMSC 432. UMBC More Patterns2 Introduction Over the next few lectures we’ll have an introduction to a number of patterns.
Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 1 Mediator Abbas Rasoolzadegan.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Design Pattern: Mediator Mediator Modified from Kyle Kimport’s: Design Patterns: Mediator Design Patterns: Mediator Ref:
A Behavioral Pattern. Problem: Simple enough right? Object.
Observer Pattern Fall 2005 OOPD John Anthony. What is a Pattern? “Each pattern describes a problem which occurs over and over again in our environment,
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Cam Quach Joel Derstine Mediator: Object Behavioral.
Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-1 PS95&96-MEF-L16-1 Dr. M.E. Fayad Creationa l.
Mediator A Behavioral Design Pattern for the New Millennium Cory Nugent.
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
BY VEDASHREE GOVINDA GOWDA
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
A Behavior Object Pattern
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Emeka Egbuonye CSPP March 02,2010 The Mediator Pattern.
Case Studies on Design Patterns Design Refinements Examples.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
GRASP: Designing Objects with Responsibilities
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Structural Design Patterns
Mediator Kensho Tsuchihashi. Mediator Page 2 Table of Contents 1.What is Mediator? 2.What problem does Mediator solve? 3.Advantage and Disadvantage 4.Additional.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
The Template Method Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
The Observer Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Behavioral Pattern: Mediator C h a p t e r 5 – P a g e 169 When a program is made up of several classes, the logic and computation is divided among these.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
OBSERVER PATTERN OBSERVER PATTERN Presented By Presented By Ajeet Tripathi ISE
The Observer Design Pattern Author :Erich Gamma, et al. Source :Elements of Reusable Object-Oriented Software Speaker : Chiao-Ping Chang Advisor : Ku-Yaw.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Patterns An Easier Way to Think About Common Software Designs This presentation is licensed under a Creative Commons License.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Software Design Refinement Using Design Patterns
Mediator Design Pattern
Observer Design Pattern
Instructor: Dr. Hany H. Ammar
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Multiuser Protection and the Mediator Pattern
Mediator Design Pattern (Behavioral)
Mediator.
Presentation transcript:

The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1

Mediator in the Real World ©SoftMoore ConsultingSlide 2

Motivation Consider a situation where many objects need to communicate with each other. In the worst case, every object needs to know about every other object. The lines of communication can become overly complex and can inhibit reuse of the classes outside of the application context. In some cases communication between the objects can be simplified by introducing an intermediate “mediator” object. Communication between the various application objects goes through the mediator. The mediator takes on the role of a hub or router and facilitates communication between the application classes. ©SoftMoore ConsultingSlide 3

Motivation (continued) ©SoftMoore ConsultingSlide 4 Without a MediatorWith a Mediator O1O1O2 O1O1 O1O1 O3 O1O1O1O1 O1O1 O1O1 O1O1M 10 possible paths of communication 5 possible paths of communication

Motivation (continued) Consider the implementation of a dialog box as part of a graphical user interface. A dialog box can contain a collection of widgets such as buttons, text fields, menus, list boxes, etc., with dependencies between the widgets. The individual widgets should be reusable in different dialog boxes, so they must be designed without knowledge of each other. One approach would be to create application-specific subclasses of the widgets with knowledge of the other widgets in the dialog box. ©SoftMoore ConsultingSlide 5

Motivation (continued) A more general approach is to create mediator that is responsible for controlling and coordinating the interactions of the widgets in the dialog box. Often, the dialog box itself can be used as the mediator. ©SoftMoore ConsultingSlide 6

Mediator Pattern 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. 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 subclassing. Slide 7©SoftMoore Consulting

Mediator Pattern (continued) ©SoftMoore ConsultingSlide 8 MediatorColleague ConcreteMediatorConcreteColleague1ConcreteColleague2 Structure

Mediator Pattern (continued) ©SoftMoore ConsultingSlide 9 : ConcreteMediator Typical Object Diagram : Colleague mediator : Colleague mediator : Colleague mediator : Colleague mediator : Colleague mediator

Mediator Pattern (continued) Participants Mediator –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 knows its mediator object. –each colleague communicates with its mediator whenever it would have otherwise communicated with another colleague. ©SoftMoore ConsultingSlide 10

Mediator Pattern (continued) Collaborations Colleagues send and receive requests from a Mediator object. The mediator implements the cooperative behavior by routing requests between appropriate colleagues. ©SoftMoore ConsultingSlide 11

Mediator Pattern (continued) Consequences It limits subclassing. A mediator localizes behavior that otherwise would be distributed among several objects. Changing this behavior requires subclassing Mediator only; Colleague classes can be reused as is. It decouples colleagues. A mediator promotes loose coupling between colleagues. You can vary and reuse Colleague and Mediator classes independently. It simplifies object protocols. A mediator replaces many-to- many interactions with one-to-many interactions between the mediator and its colleagues. One-to-many relationships are easier to understand, maintain, and extend. ©SoftMoore ConsultingSlide 12

Mediator Pattern (continued) Consequences (continued) It abstracts how objects cooperate. Making mediation an independent concept and encapsulating it in an object lets you focus on how objects interact apart from their individual behavior. That can help clarify how objects interact in a system. It centralized control. The Mediator pattern trades complexity of interaction for complexity in the mediator. Because a mediator encapsulates protocols, it can become more complex than any individual colleague. This can make the mediator itself a monolith that is hard to maintain. ©SoftMoore ConsultingSlide 13

Mediator Pattern (continued) Implementation There is 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. Colleagues have to communicate with their mediator when an event of interest occurs. –One approach is to implement Mediator as an Observer, where Colleagues notify the mediator whenever they change state and mediator propagates the change to other colleagues. –Another approach is to define a specialize communication interface in Mediator. ©SoftMoore ConsultingSlide 14

Mediator Pattern in Java Most systems that facilitate asynchronous messaging implement some form of message bus as a mediator. The Java Message Service (JMS) is a messaging API that allows application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous. JMS implementations –IBM MQ is a commercial implementation –Apache ActiveMQ is an open source implementation ©SoftMoore ConsultingSlide 15

Related Patterns Façade differs from Mediator in that it abstracts a subsystem of objects to provide a more convenient interface. Its protocol is unidirectional; that is, Façade objects make requests of subsystem classes, but not vice versa. In contrast, Mediator enables cooperative behavior, and the protocol is multidirectional. Colleagues can communicate with the mediator using the Observer pattern. (Note: JMS allows objects to communicate using this pattern.) ©SoftMoore ConsultingSlide 16

References Mediator pattern (Wikipedia) Mediator Pattern (Object-Oriented Design) Mediator Design Pattern (SourceMaking) Open Message Queue ©SoftMoore ConsultingSlide 17