A Behavioral Pattern. Problem: Simple enough right? Object.

Slides:



Advertisements
Similar presentations
COMP171 Fall 2005 Lists.
Advertisements

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 Patterns CMPS Design Patterns Consider previous solutions to problems similar to any new problem ▫ must have some characteristics in common.
Visibility Information Exchange Web System. Source Data Import Source Data Validation Database Rules Program Logic Storage RetrievalPresentation AnalysisInterpretation.
CS 11 java track: lecture 7 This week: Web tutorial:
Design Pattern: Mediator Mediator Modified from Kyle Kimport’s: Design Patterns: Mediator Design Patterns: Mediator Ref:
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Design Patterns CS is not simply about programming
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Stéphane Ducasse6.1 Essential Concepts Why OO? What is OO? What are the benefits? What are the KEY concepts? Basis for all the lectures.
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.
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Fundamentals of Python: From First Programs Through Data Structures
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Who am I? ● Catalin Comanici ● QA for 10 years, doing test automation for about 6 years ● fun guy and rock star wannabe.
BY VEDASHREE GOVINDA GOWDA
Multiple Choice Solutions True/False a c b e d   T F.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Design Patterns.
A Behavior Object Pattern
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Emeka Egbuonye CSPP March 02,2010 The Mediator Pattern.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Architectures Classic Client/Server Architecture Classic Web Architecture N-tier (multi-tier) Architecture FEN Databaser og Modellering.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 10 Use Case Design.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
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.
GRASP: Designing Objects with Responsibilities
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Information System Design (IT60105) Lecture 26 Object-Oriented System Testing.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Design Patterns Yonglei Tao. Design Patterns  A design pattern describes a recurring design problem, a solution, and the context in which that solution.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
OPERATING SYSTEMS Frans Sanen.  Recap of threads in Java  Learn to think about synchronization problems in Java  Solve synchronization problems in.
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.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Broker Design Patterns: Façade and Mediator.
Façade Design Pattern by Ali Alkhafaji Unified interface for a set of interfaces to promote readability and usability.
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.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Module dependences and decoupling CSE 331 University of Washington.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Mediator Design Pattern
University of Central Florida COP 3330 Object Oriented Programming
Chapter 5:Design Patterns
MPCS – Advanced java Programming
University of Central Florida COP 3330 Object Oriented Programming
Mediator Design Pattern (Behavioral)
State Design Pattern Brandon Jacobsen.
Presentation transcript:

A Behavioral Pattern

Problem: Simple enough right? Object

Problem: How about now? Object

What does it do? Encapsulates object-to-object communication. Handles the many-to-many relationship Keeps objects from knowing about each other Keeps things modular and simple Allows for the addition and subtraction of classes at any time in the development phase. Keeps the code pretty.

Solution: Better! Object Mediator Now you can insert as many objects as you want without fear of breaking the code! Note the connections now have direction.

When to use: Reusing an object over and over When multiple objects are interacting in multiple ways with several different objects When centralized control is desired When simple objects need to communicate in complex ways

Key Parts There are two main parts to a Mediator Pattern: Colleagues – The object(s) that are interacting with one another. Mediator – The object that will facilitate said interactions. There is only one mediator, but there are always two or more colleagues.

Pros and Cons Pros: Facilitates decoupling, this allows for reuse Keeps communication simple, allowing for easier maintenance. Limits sub-classing and specialization, also allowing for reuse. Simplifies overall architecture by taking a many-to- many relationship to a one-to-many relationship.

Pros and Cons Cons: As complexity is reduced in the colleagues, it increases in the mediator It’s difficult to keep the mediator from being an all controlling class It’s meant to facilitate, not control the data/logic flow. On the flip side, limiting sub-classing and specialization can limit functionality of the project.

Similar, but Different The mediator pattern is similar to the observer class, but it facilitates communication between existing objects in their current state, it does not create observers. The mediator patter is also similar to the façade pattern, however there is a two way communication between the mediator class and the colleague classes.

Code Example // The mediator class class Mediator { private int Number; public void store( int num ) { // no room for another producer while (full == true) { wait(); } // store the number Number = num; // notify the notifyAll(); } public int retrieve() { // no message to retrieve while (full == false) { wait(); } full = false; // notify the notifyAll(); // return the number return number; } }// end class mediator

Producer Class class Producer extends Thread { // Only contains a Mediator object, not a consumer object private Mediator med; private int number; // constructor public Producer( Mediator m ) { med = m; // a unique producer each time number = number++; } // produce public void driver() { while (true) { med.storeMessage( number ); System.out.print( number + “\n” ); } }// end class producer

Consumer Class class Consumer extends Thread { // only contains a mediator object private Mediator med; private int number; //constructor public Consumer( Mediator m ) { med = m; number = number++; } //consume public void driver() { while (true) { System.out.println(number); } }//end class consumer

Code Example The two colleagues only communicate with the mediator. The mediator only controls the communication pathways, NOT the actual logic or control. The two classes only need to know what they should do, they do not need a sizeable knowledge of the program as a whole (or any other class but the mediator).