Copyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-1 PS95&96-MEF-L16-1 Dr. M.E. Fayad Creationa l.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Creational Patterns - Page L4-1 PS95&96-MEF-L11-1 Dr. M.E. Fayad Creationa l Paradigm.
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.
Lecture 12 Observer Pattern UML Class Diagrams (repetition) Use Case Diagrams Sequence Diagrams Statechart Diagrams.
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Chapter 7 – Object-Oriented Design
CSE3308/CSC Software Engineering: Analysis and DesignLecture 5B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/CSC3080/DMS/2000/12.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
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,
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Structural Patterns - Page L6-1 PS95&96-MEF-L13-1 Dr. M.E. Fayad Creationa l Paradigm.
Observer Pattern Tu Nguyen. General Purpose When one object changes state, all the dependent objects are notified and updated. Allows for consistency.
Copyright © 1995 –2004 Active Frameworks Inc. - All Rights Reserved - V2.0Behavioral Patterns - Page L8-1 PS95&96-MEF-L15-1 Dr. M.E. Fayad Creationa l.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Copyright © Active Frameworks, Inc.. - All Rights Reserved - V2.0 Introduction - Page L1-1 PS95&96-MEF-L1-1 Dr. M.E. Fayad Creationa l Paradigm.
Cam Quach Joel Derstine Mediator: Object Behavioral.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
BY VEDASHREE GOVINDA GOWDA
MVC pattern and implementation in java
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Implementing Design Patterns Using Java St. Louis Java Special Interest Group Eric M. Burke Object Computing, Inc. Presented on July 9, 1998 (updated July.
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.
Observer Behavioral Pattern. Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
Programming in C# Observer Design Pattern
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 VII Observer, Command, and Memento.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Where Do Surrogates Fit into This Proxy Pattern Observer Pattern Visitor Pattern By Kurt Rehwinkel.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Proxy, Observer, Symbolic Links Rebecca Chernoff.
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.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
OBSERVER DESIGN PATTERN. Behavioral Patterns  Behavioral patterns are those patterns that are most specifically concerned with communication between.
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.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Pattern Bridge. Definition Bridge is the structural pattern that separates abstraction from the implementation so that both of them can be changed independently.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
The Observer Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
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.
High degree of user interaction Interactive Systems: Model View Controller Presentation-abstraction-control.
February 23, 2009Observer Pattern, OOA&D, Rubal Gupta, CSPP, Winter ‘09 Observer Pattern Defines a “one-to-many” dependency between objects so that when.
Observer Design Pattern
Design Patterns with C# (and Food!)
Presented by Igor Ivković
Design Patterns - A few examples
Web Programming Language
Mediator Design Pattern (Behavioral)
Observer Pattern 1.
Lesson 5: More on Creational Patterns
Presentation transcript:

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 Paradigm Shift, Inc. Software Factory Behaviora l Structural Lesson 9: More On Behavioral Patterns Object-Oriented Design Patterns

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-2 PS95&96-MEF-L16-2 Dr. M.E. Fayad Lesson Objectives oPresent the following Patterns: Mediator Observer oDiscuss in detail the behavioral patterns

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-3 PS95&96-MEF-L16-3 Dr. M.E. Fayad Behavioral Patterns  Mediator Pattern Topics –Mediator Definition –Structure –Graphic UI Example –Problems it Solves –Participants –Benefits –Related Patterns

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-4 PS95&96-MEF-L16-4 Dr. M.E. Fayad Mediator Pattern: Definition Mediator object coordinates communication between interacting objects. Interacting objects work with and through a Mediator rather than each other directly. The Mediator pattern is also known as a “glue” pattern. The Mediator pattern decouples the individual tasks. –Each object only knows its own input and output. –This way, each object does not depend on the other objects around it.

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-5 PS95&96-MEF-L16-5 Dr. M.E. Fayad Mediator Pattern: Illustration Client or User Object A Object C Object D Object B The “Before” Model

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-6 PS95&96-MEF-L16-6 Dr. M.E. Fayad Mediator Pattern: More Illustration Client or User Object A Object C Object D Object B The “After” Model Mediator Object Abstraction Colleague objects

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-7 PS95&96-MEF-L16-7 Dr. M.E. Fayad Mediator Pattern: Structure Mediator colleague classes

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-8 PS95&96-MEF-L16-8 Dr. M.E. Fayad Dialog Director Example DialogDirector ShowDialog() CreateControls() HandleChange(Control) Control Select() director-> HandleChange(this) EntryField director ListDialog CreateControls() HandleChange(Control) ListBox DialogDirector is an abstract class that defines the overall infrastructure of a dialog. It keeps a reference to the window that presents the dialog. Clients call the ShowDialog operation to display the dialog on the screen. CreateControls and HandleChange are abstract operations. DialogDirector subclasses override CreateControls to create the proper controls and HandleChange to handle the changes. DialogDirector is an abstract class that defines the overall infrastructure of a dialog. It keeps a reference to the window that presents the dialog. Clients call the ShowDialog operation to display the dialog on the screen. CreateControls and HandleChange are abstract operations. DialogDirector subclasses override CreateControls to create the proper controls and HandleChange to handle the changes.

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-9 PS95&96-MEF-L16-9 Dr. M.E. Fayad Dialog Director Example: Interaction Diagram GetSelection DialogDirector Colleague Client SetText HandleChange ListBox ShowDialog Mediator EntryField

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-10 PS95&96-MEF-L16-10 Dr. M.E. Fayad Mediator Pattern: Participants & Collaborations Mediator (DialogDirector) –implements cooperative behavior by coordinating Colleague objects. –stores state. Colleague classes (ListBox, EntryField) –implements pieces of the cooperative behavior. Collaborations Colleagues send/receive requests to/from a Mediator object. The Mediator implements the cooperative behavior by routing requests between the appropriate Colleague(s). Collaborations Colleagues send/receive requests to/from a Mediator object. The Mediator implements the cooperative behavior by routing requests between the appropriate Colleague(s). Participants

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-11 PS95&96-MEF-L16-11 Dr. M.E. Fayad It is time for breakfast. A customer places an order and gives it to the egg cooker. The egg cooker does his job and then moves the order to the fry cook for meat and hash browns. The fry cook sends the plate on, and so forth. When the order has finished processing in the kitchen the customer’s name is called and the plate is given to the customer. This scheme is inflexible because you cannot change the structure of the kitchen and you cannot add any other steps to the cooking processes. Mediator Pattern: Restaurant Example

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-12 PS95&96-MEF-L16-12 Dr. M.E. Fayad Mediator Pattern: Restaurant Example Customer in a restaurant Eggs Toast Fry2 Fry The “Before” Model

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-13 PS95&96-MEF-L16-13 Dr. M.E. Fayad Mediator Pattern: The Solution Customer in a Restaurant Eggs Fry2 Toast Fry The “After” Model Waitperson Abstraction Colleague objects

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-14 PS95&96-MEF-L16-14 Dr. M.E. Fayad Each of the objects knows only of the Mediator existence. Each performs its task and returns its finished product to the Mediator. Flexibility is added because: –Each individual object is free to change its own methods without effecting the others and without the other’s knowledge. This allows for dynamic binding and polymorphism. –An additional process may be added. This would require a change in the Mediator object. Mediator Pattern: More on The Solution

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-15 PS95&96-MEF-L16-15 Dr. M.E. Fayad Mediator Pattern: Advantages Moves complexity out of the problem domain solution (mainline routines). Abstraction hides some non- essential implementation details. Changes or improvements to the underlying functions and objects do not require changes to client code. Frees up individual colleague objects by decoupling them. Enhances the chance for extensibility in the colleague objects since changes to individual colleagues do not ripple through to other colleagues and affect overall dependencies. Different Mediator objects can provide a different set of services to the client by reusing colleague objects.

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-16 PS95&96-MEF-L16-16 Dr. M.E. Fayad If the Mediator becomes too complex, extensibility of the Mediator may be limited without significant rework. Do not allow the Mediator to become a “special case” handler. If the degree of complexity that you are moving from the Colleague into the Mediator is small then extra overhead of Mediator development may not be justified. Decision made by the Mediator have to “jive” with what the Mainline routines expect. In other words, “Can you trust your Mediator’s decisions?” Mediator Pattern: Disadvantages

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-17 PS95&96-MEF-L16-17 Dr. M.E. Fayad When we have a group of colleagues that interact in complex but well-defined ways. When the order of individual colleague operations might change. Relieve colleague objects from the additional burden of mediation in addition to their regular services. Mediator Pattern: When It Should be Used

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-18 PS95&96-MEF-L16-18 Dr. M.E. Fayad Behavioral Patterns  Observer Pattern Topics –Observer Definition –Structure –Application Area –Problems it Solves –Participants –Benefits –Implementation Issues –Discussion Questions

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-19 PS95&96-MEF-L16-19 Dr. M.E. Fayad Observer Pattern: Definition Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. It is also known as Publish-Subscribe or Dependents The key objects in the Observer pattern are Subject and Observer. A Subject may have any number of dependent observers. All observers are notified whenever the subject undergoes a change in state. Any number of observers can subscribe to receive notifications.

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-20 PS95&96-MEF-L16-20 Dr. M.E. Fayad Observer Pattern: Structure for all o in observers { o->Update() } return subjectState Subject Attach(Observer) Detach(Observer) Notify() Observer Update() ConcreteSubject GetState() observers subjectState observerState = subject->GetState(); ConcreteObserver Update() observerState subject

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-21 PS95&96-MEF-L16-21 Dr. M.E. Fayad Observer Pattern: Applicability An object should be separated into two basic parts: –One part encapsulates state and operations that define the object independent of its context. –The other part encapsulates the mechanisms that present information in context-dependent way. A dependency between an object (Subject) and a set of other objects (Observers) is required such that the observers are notified when the subject undergoes a significant change.

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-22 PS95&96-MEF-L16-22 Dr. M.E. Fayad Observer Pattern: Participants Subject –provides an interface for attaching and detaching Observer objects –knows its Observers. Observer –defines an updating interface for objects that should be notified of changes in a Subject. ConcreteSubject –stores state of interest to ConcreteObservers –sends a notification to its Observers when its state changes ConcreteObserver –maintains a reference to its ConcreteSubject –stores state that should stay consistent with the Subject’s. –implements the Observer updating interface to keep its state consistent with the Subject’s.

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-23 PS95&96-MEF-L16-23 Dr. M.E. Fayad Observer Pattern: Collaborations Instance Diagram aConcreteSubject aConcreteObserver1 aConcreteObserver2 4. UpdateSelf 6. UpdateSelf 5. Update 1. SetState 3. Update 2. Notify

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-24 PS95&96-MEF-L16-24 Dr. M.E. Fayad Observer Pattern: Implementation Issues Issues related to the implementation of the dependency mechanisms: 1. Mapping Subjects to their Observers 2. Avoiding Dangling References to Deleted Subjects 3. Ensuring Self-Consistency of Subject State 4. Avoiding Observer-Specific Update Protocols: The Push and Pull Models 5. Explicitly specifying Modifications of Interest 6. Encapsulating Complex Update Semantics

Copyright © Active Frameworks Inc. - All Rights Reserved.More On Behavioral Patterns - Page L9-25 PS95&96-MEF-L16-25 Dr. M.E. Fayad Discussion Questions o (T) for true or (F) for false ( ) 1. The Mediator pattern replaces many-to-many interactions with one-to-many ones between mediator and colleagues, which are easier to understand, maintain, and extend. ( ) 2. A common use of the Mediator pattern is to keep track of instances of a certain class. ( ) 3. One of the application of the Mediator pattern is to coordinate complex updates. ( ) 4. The Mediator pattern coordinate communication between interacting objects. ( ) 5. The Observer pattern objectifies the notions of context- dependent and context-independent state, permitting them to be varied independently. ( ) 6. The key objects in the Observer pattern are subject and observers. ( ) 7. An Observer pattern should be used when an object has to notify other objects without making any assumptions about who these objects are.