Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 1 Mediator Abbas Rasoolzadegan.

Slides:



Advertisements
Similar presentations
Creational Patterns, Abstract Factory, Builder Billy Bennett June 11, 2009.
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.
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:
Lecture 13 UML diagrams state-chart diagrams Design Pattern.
A Behavioral Pattern. Problem: Simple enough right? Object.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Component-Level Design
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.
Design Patterns CS is not simply about programming
Façade Pattern Jeff Schott CS590L Spring What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance.
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.
Applying Design Patterns to Wireless Sensor Network Sajjad Soroush AmirKabir University of Technology, Department of Computer Engineering.
OOMPA Lecture 10 Design Patterns Singleton Factory Method
Mediator A Behavioral Design Pattern for the New Millennium Cory Nugent.
E. Kraemer CSE 335: Software Design Administrivia Exam 2 : Wednesday, March pm Room: TBA Wed, March 12th - exam outline in class Mon, March 17th.
Façade Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
BY VEDASHREE GOVINDA GOWDA
The Design Discipline.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
A Behavior Object Pattern
Emeka Egbuonye CSPP March 02,2010 The Mediator Pattern.
Case Studies on Design Patterns Design Refinements Examples.
SOFTWARE DESIGN AND ARCHITECTURE
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
Pattern Hatching - John Vlissides Pages 85 – 101 Todd Anderson
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
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.
Design Patterns Structural Patterns. Adapter Convert the interface of a class into another interface clients expect Adapter lets classes work together.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
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.
Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since 1987 Program Director, Los Angeles Visual Foxpro Developers.
The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
BTS430 Systems Analysis and Design using UML
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.
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
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Mediator Design Pattern
Observer Design Pattern
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by Igor Ivković
Multiuser Protection and the Mediator Pattern
Mediator Design Pattern (Behavioral)
Mediator.
Object Oriented Design Patterns - Structural Patterns
Informatics 122 Software Design II
Presented by Igor Ivković
Presentation transcript:

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 1 Mediator Abbas Rasoolzadegan

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 2 فرم نمونه براي رزور يک اتاق مهماني در يک هتل

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 3 Interactions

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 4 Next Example: a dialog box in a graphical user interface

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 5 Problem Object oriented design encourages the distribution of behavior among the various objects  increasing reusability (high cohesion)  decreasing reusability (high coupling) through proliferating interactions every object knows about every other  changing the system’s behavior will be difficult

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 6 Solution Use mediator design pattern  Define an object,mediator, that encapsulates how a set of objects interact promotes loose coupling by keeping objects from referring to each other explicitly lets you vary their interaction independently is generally, responsible for controlling and coordinating the interactions of a group of objects  Classification: Object Behavioral

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 7 interactions between the objects of a dialog box through a mediator

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 8 Sequence Diagram

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 9 Events: 1. The list box tells its director that it has changed. 2. The director gets the selection from the list box. 3. The director passes the selection to the entry field. 4. Now that the entry field contains some text, the director enables button(s) for initiating an action.

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 10 Class Diagram

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 11

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 12 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.

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 13 Structure

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 14 A typical object structure

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 15 Participants Mediator  defines an interface for communicating with colleague objects ConcreteMediator  implements cooperative behavior, knows and maintains its colleagues Colleague classes  knows its mediator object, communication with mediator as opposed to other objects

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 16 Consequences It limits subclassing  A mediator localize 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  Vary and reuse independently It simplifies object protocols  Many-to-many interactions are replaced with one-to-many which are easier to understand, maintain, and extend It abstracts how objects cooperate  Clarify how objects interact in a system It centralizes control

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 17 Disadvantage Increased complexity of the mediator. Mediator becomes a monolithic structure that is hard to maintain

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 18 Implementation Issues Omitting the abstract mediator class  When colleagues work with only one mediator Implement Colleague-Mediator communication using  observer pattern  a specialized notification (see in sample code)

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 19 Sample Code class DialogDirector { public: virtual ~DialogDirector(); virtual void ShowDialog(); virtual void WidgetChanged(Widget*) = 0; protected: DialogDirector(); virtual void CreateWidgets() = 0; }; class Widget { public: Widget(DialogDirector*); virtual void Changed(); virtual void HandleMouse(MouseEvent& event); //... private: DialogDirector* _director; }; void Widget::Changed () { _director->WidgetChanged(this); } class ListBox : public Widget { public: ListBox(DialogDirector*); virtual const char* GetSelection(); virtual void SetList(List * listItems); virtual void HandleMouse(MouseEvent& event); //... }; class EntryField : public Widget { public: EntryField(DialogDirector*); virtual void SetText(const char* text); virtual const char* GetText(); virtual void HandleMouse(MouseEvent& event); //... }; class Button : public Widget { public: Button(DialogDirector*); virtual void SetText(const char* text); virtual void HandleMouse(MouseEvent& event); //... }; void Button::HandleMouse (MouseEvent& event) { //... Changed(); }

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 20 class FontDialogDirector : public DialogDirector { public: FontDialogDirector(); virtual ~FontDialogDirector(); virtual void WidgetChanged(Widget*); protected: virtual void CreateWidgets(); private: Button* _ok; Button* _cancel; ListBox* _fontList; EntryField* _fontName; }; void FontDialogDirector::CreateWidgets () { _ok = new Button(this); _cancel = new Button(this); _fontList = new ListBox(this); _fontName = new EntryField(this); // fill the listBox with the available font names // assemble the widgets in the dialog } WidgetChanged ensures that the widgets work together properly: void FontDialogDirector::WidgetChanged ( Widget* theChangedWidget ) { if (theChangedWidget == _fontList) { _fontName->SetText(_fontList->GetSelection()); } else if (theChangedWidget == _ok) { // apply font change and dismiss dialog } else if (theChangedWidget == _cancel) { // dismiss dialog }

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 21 Related Patterns Façade: Abstracts a subsystem of objects providing a more convenient interface  Difference with mediator: Façade is an structural pattern but mediator is a behavioral pattern In Façade, Protocol is unidirectional as opposed to mediator. Mediator is a “two-way” version of façade Façade promotes weak coupling between the subsystem classes and its client but mediator promotes weak coupling between a set of objects Façade shields clients from subsystem components, but mediator shields objects of a set from each other Colleagues can communicate with the mediator using the Observer pattern

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 22 Questions???? Thank You!!