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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Amirkabir University of Technology, Computer Engineering Faculty, Intelligent Systems Laboratory 1 Mediator Abbas Rasoolzadegan.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
VLANs Virtual LANs CIS 278.
Behavioral Pattern: Template Method C h a p t e r 5 – P a g e 217 On occasion, two different components in a software system will have significant similarities,
8.
A Behavioral Pattern. Problem: Simple enough right? Object.
Metropolitan Ethernet Networks Estella Kang Matt Powers SC441 Computer Networks – Independent Study Boston University.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
Cam Quach Joel Derstine Mediator: Object Behavioral.
Mediator A Behavioral Design Pattern for the New Millennium Cory Nugent.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Cambodia-India Entrepreneurship Development Centre - : :.... :-:-
Computer Networks IGCSE ICT Section 4.
Copyright Kenneth M. Chipps Ph.D. 1 VPN Last Update
Virtual LANs. VLAN introduction VLANs logically segment switched networks based on the functions, project teams, or applications of the organization regardless.
Behavioral Pattern: Memento C h a p t e r 5 – P a g e 179 Objects frequently expose only some of their internal state using public methods, but there.
Behavioral Patterns C h a p t e r 5 – P a g e 128 BehavioralPatterns Design patterns that identify and realize common interactions between objects Chain.
BY VEDASHREE GOVINDA GOWDA
The Design Discipline.
A Behavior Object Pattern
Firewalls Paper By: Vandana Bhardwaj. What this paper covers? Why you need a firewall? What is firewall? How does a network firewall interact with OSI.
Smart Reference Proxy Provides additional actions whenever an object is referenced (e.g., counting the number of references to the object) Firewall Proxy.
1 CMPT 275 High Level Design Phase Architecture. Janice Regan, Objectives of Design  The design phase takes the results of the requirements analysis.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public ITE PC v4.0 Chapter 1 1 Connecting to the Network Networking for Home and Small Businesses.
Emeka Egbuonye CSPP March 02,2010 The Mediator Pattern.
Case Studies on Design Patterns Design Refinements Examples.
Multi-Protocol Label Switching University of Southern Queensland.
 Network Segments  NICs  Repeaters  Hubs  Bridges  Switches  Routers and Brouters  Gateways 2.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
Behavioral Pattern: Command C h a p t e r 5 – P a g e 139 There are times when the need arises to issue a request to an object without knowing anything.
Behavioral Pattern: Observer C h a p t e r 5 – P a g e 186 A large monolithic design does not scale well as additional graphical and monitoring requirements.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Chapter 21 Topologies Chapter 2. 2 Chapter Objectives Explain the different topologies Explain the structure of various topologies Compare different topologies.
Computing IV Singleton Pattern Xinwen Fu.
The Intranet.
Structural Pattern: Bridge When the abstract interface and the concrete implementation have been set up as parallel class hierarchies, it becomes difficult.
Behavioral Pattern: Strategy C h a p t e r 5 – P a g e 205 The Open-Closed Principle advocates designing software in such a way that it will absorb new.
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.
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
Design Patterns Structural Patterns. Adapter Convert the interface of a class into another interface clients expect Adapter lets classes work together.
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.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Chain of Responsibility Behavioral Pattern. Defination Avoid coupling between the sender and receiver by giving more than one object a chance to handle.
Creational Pattern: Builder When a complex object needs to be created, it is sometimes beneficial to separate the construction of the object from its.
The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
Network Virtualization Sandip Chakraborty. In routing table we keep both the next hop IP (gateway) as well as the default interface. Why do we require.
Structural Patterns C h a p t e r 4 – P a g e 55 StructuralPatterns Design patterns that describe how classes and objects can be combined to form larger.
NETWORKS Network Topologies / Configurations. Learning Objectives Describe for each type of network topology the relative strengths and weaknesses.
Creational Patterns C h a p t e r 3 – P a g e 14 Creational Patterns Design patterns that deal with object creation mechanisms and class instantiation,
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Mediator Design Pattern
The Intranet.
Internet and Intranet.
Creational Pattern: Prototype
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Internet and Intranet.
Unit 27: Network Operating Systems
Multiuser Protection and the Mediator Pattern
Mediator Design Pattern (Behavioral)
Mediator.
Pointers & Functions.
Internet and Intranet.
Virtual LAN VLAN Trunking Protocol and Inter-VLAN Routing
Pointers & Functions.
Internet and Intranet.
Presentation transcript:

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 classes. However, as more classes are developed, the problem of communication between them becomes more complex. This makes the program harder to read and to maintain. Further, it can become difficult to change the program, since any change may affect code in several other classes. The Mediator Pattern addresses this problem by promoting looser coupling between the classes. The Mediator is the only class that has detailed knowledge of the methods of other classes. Classes inform the Mediator when changes occur and the Mediator passes them on to any other classes that need to be informed.

The Mediator Pattern C h a p t e r 5 – P a g e 170 The Mediator provides the interface for communicating with Colleague objects. The ConcreteMediator knows and maintains its Colleagues, and implements cooperative behavior by coordinating the Colleague objects. Each Colleague class knows its Mediator object, communicating with it whenever it would have otherwise communicated with another Colleague.

C h a p t e r 5 – P a g e 171 Non-Software Example: ATC The pilots of the planes (the Colleagues) approaching or departing the terminal area communicate with the tower (the Mediator) rather than explicitly communicating with one another. The constraints on who can take off or land are enforced by the tower. Notice that the tower does not control the whole flight. It exists only to enforce constraints in the terminal area.

C h a p t e r 5 – P a g e 172 Software Example: Label Switched Paths Consider a complex managed network, offering a variety of services, including Internet telephony and data applications ( , server access, application access, etc.). A label switched path (LSP) is a forwarding path for traffic. The advantage of using LSPs rather than merely relying on IP forwarding is that LSPs provide more detailed control of the network. Path and Quality-of-Service (QoS) configuration data (the Colleagues) is dynamically maintained by a connection director (the Mediator) who continually adjusts and reconfigures the LSP.

C h a p t e r 5 – P a g e 173 LSP Mediator Code in C++ #include using namespace std; class Widget; class ConnectionDirector { public: explicit ConnectionDirector() {} virtual ~ConnectionDirector() {} virtual void WidgetChanged(Widget*) = 0; protected: ConnectionDirector(int); virtual void CreateWidgets() = 0; }; class Widget { public: explicit Widget(ConnectionDirector* aConnDirector) { director = aConnDirector; } virtual void Changed() { director->WidgetChanged(this); } protected: ConnectionDirector* director; };

C h a p t e r 5 – P a g e 174 class PathWidget : public Widget { public: explicit PathWidget(ConnectionDirector* theDirector) : Widget(theDirector) {} virtual ~PathWidget() {} void CreateInitialPath(char* newPath) { pathDetails = newPath; cout << "Initial path setting: " << pathDetails << endl; } void getNewPath() { cout << "The PathWidget path is: " << pathDetails << endl; } void ChangePath(char* newPath) { pathDetails = newPath; cout << "The updated PathWidget path is: " << pathDetails << endl; Changed(); } private: char* pathDetails; };

C h a p t e r 5 – P a g e 175 class QosWidget : public Widget { public: explicit QosWidget(ConnectionDirector* theDirector) : Widget(theDirector) {} virtual ~QosWidget() {} void CreateInitialQoS(char* initialQoSDetails) { QoSDetails = initialQoSDetails; cout << "Initial QoS setting: " << QoSDetails << endl; } void getNewQoS() { cout << "The QosWidget details are: " << QoSDetails << endl; } void ChangeQoSDetails(char* newQoSDetails) { QoSDetails = newQoSDetails; cout << "The updated QosWidget QoS details are " << QoSDetails << endl; Changed(); } private: char* QoSDetails; };

C h a p t e r 5 – P a g e 176 class LspDirector : public ConnectionDirector { public: explicit LspDirector(int anLspId) {lspId = anLspId; } virtual ~LspDirector() {} virtual void WidgetChanged(Widget* imAChangedWidget) { if (imAChangedWidget == lspPath) // Change the path used by the LSP cout << "Director informed of change to LSP Path" << endl; else if (imAChangedWidget == qosDescriptor) // Change the Qos resources used by the LSP cout << "Director informed of change to QoS Resources" << endl; } virtual void CreateWidgets() { lspPath = new PathWidget(this); lspPath->CreateInitialPath("R2R3R4R5"); qosDescriptor = new QosWidget(this); qosDescriptor->CreateInitialQoS("Assured Forwarding"); } void ChangePath(char* newPath) { lspPath->ChangePath(newPath); } void ChangeQoSDetails(char* newQoS) { qosDescriptor->ChangeQoSDetails(newQoS); } private: int lspId; PathWidget* lspPath; QosWidget* qosDescriptor; };

C h a p t e r 5 – P a g e 177 void main() { LspDirector* anExampleMediator = new LspDirector(555); // Create several widgets for the LSP anExampleMediator->CreateWidgets(); anExampleMediator->ChangePath("R2R6R5"); anExampleMediator->ChangeQoSDetails("Expedited Forwarding"); delete anExampleMediator; return; }

Mediator Pattern Advantages C h a p t e r 5 – P a g e 178 The Mediator makes loose coupling possible between objects in a program. It also localizes the behavior that otherwise would be distributed among several objects. The Mediator approach makes it possible to add new Colleagues to a system without having to change any other part of the program. In addition, the behavior of the program can be changed by simply changing or subclassing the Mediator. The Mediator can become monolithic in complexity, making it hard to change and maintain. This situation can sometimes be improved by revising the responsibilities given to the Mediator. Each object should carry out its own tasks and the Mediator should only manage the interaction between objects.