Zaki Alasadi 87231101 Supervisor:Dr noorhosseini.

Slides:



Advertisements
Similar presentations
Chain of Responsibility Pattern Gof pp Yuyang Chen.
Advertisements

1 Microsoft Access 2002 Tutorial 9 – Automating Tasks With Macros.
The New The Old And the Annoying! SES. THE NEW… 10 new vendors have been added to our list for a total of 39 providers 10 District/Leas have been added.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Matt Klein 7/2/2009.  Intent  Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
What is the Chain? It’s a behavioral design pattern. It deals with how objects make requests and how they are handled.
Twin A Design Pattern for Modeling Multiple Inheritance Mahmoud ghorbanzadeh.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
Algorithm Programming Behavioral Design Patterns Bar-Ilan University תשס " ו by Moshe Fresko.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
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
PROG Mobile Java Application Development PROG Mobile Java Application Development Event Handling Creating Menus.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
1 Ivan Marsic Rutgers University LECTURE 18: Design Patterns Command, Decorator, State, Proxy.
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F 楊汝康 R 徐德皓 R 高稚翔.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Lexi case study (Part 2) Presentation by Matt Deckard.
Chain of Responsibility Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
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.
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.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton 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.
Chain of Responsibility A graphical user interface and a user that needs help; a security system with multiple sensors; a banking automated coin storage.
Design Patterns Introduction
Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since 1987 Program Director, Los Angeles Visual Foxpro Developers.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 31. Review Creational Design Patterns – Singleton Pattern – Builder Pattern.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
S.Ducasse Stéphane Ducasse 1 Decorator.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
(c) University of Washington10-1 CSC 143 Java Errors and Exceptions Reading: Ch. 15.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
S.Ducasse Stéphane Ducasse 1 Adapter.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
GUI- Model-View-Controller
Observer Design Pattern
Leftover Patterns Chain of Responsibility
Design Patterns Satya Puvvada Satya Puvvada.
Jim Fawcett CSE776 – Design Patterns Summer 2003
Behavioral Patterns Part-I introduction UNIT-VI
Behavioral Design Pattern
Strategy Design Pattern
Design pattern Lecture 6.
Decorator Pattern.
Software Design Lecture 11.
GUI- Model-View-Controller
Presentation transcript:

Zaki Alasadi Supervisor:Dr noorhosseini

Intent Motivation Applicability Structure Participants Implementation Consequences Example Related patterns Attention 2

Intent Avoid coupling sender of request to its receiver by giving more than one object chance to handle request. Chain receiving objects and pass request along until an object handles it. 3

Consider a context sensitive help facility for a GUI The user can obtain help information on any part of the interface just by clicking on it. The help that is provided depend on the parts of the interface that’s selected and its context. Sometimes we will encounter with help about a particular button, a particular dialog, or the application in general based on whether help is available on that subject 4

the help information is organized according to its generality - from the most specific to the most general The problem is that the object that ultimately provides the help is not known explicitly to the object that initiates the help request We need a way to decouple the button that initiates the help request from the objects that provide help information 5

The first object in the chain receives the request and will either handle it or forward it to the next object on the chain and so on. The important thing to remember, is that the object that made the request, has no knowledge of which object is handling the request. The request has an implicit receiver. 6

To forward request along the chain, and to ensure receivers remain implicit, Each object in the chain can share a common interface for handling requests and accessing its successor on the chain. 7

When more than one object may handle a particular request and the handler isn’t known ahead of time When you want to issue a request to one of several objects without specifying the receiver explicitly When the set of objects to handle a request should be specified dynamically 8

Structure 9

Handler defines an interface for handling the requests (optional) implements the successor link ConcreteHandler handles requests it is responsible for can access its successor if the ConcreteHandler can handle the request, it does so; otherwise it forwards the request to its successor Client initiates the request to a ConcreteHandler object on the chain 10

Implementing the successor chain Define new links (in Handler or ConcreteHandler) Use existing links (such as the parent references from the Composite pattern) Connecting successors Representing requests 11

12

13

14

15

+Reduced Coupling The sender doesn’t need to know the specific receiver and the receiver doesn’t need to know the sender +Added flexibility in assigning responsibilities to objects By changing the chain you can change responsibilities for handling a request at run time –Receipt Isn’t Guaranteed A request may fall off the end of the chain 16

Whenever you spend company's money, you need get approval from your boss, or your boss's boss. Let's say, the leadership chain is: Manager-->Director-->Vice President-->President abstract class Approver { protected final double base = 500; protected Approver successor; public void setSuccessor(Approver successor){ this.successor = successor; } abstract public void processRequest(PurchaseRequest request); } class Manager extends Approver { private final double ALLOWABLE = 10 * base; public void processRequest(PurchaseRequest request ) { if( request.getAmount() < ALLOWABLE ) System.out.println("Manager will approve $"+ request.getAmount()); else if( successor != null) successor.processRequest(request); }

Manager manager = new Manager(); Director director = new Director(); VicePresident vp = new VicePresident(); President president = new President() manager.setSuccessor(director); director.setSuccessor(vp); vp.setSuccessor(president); try{ while (true) { System.out.println("Enter the amount to check who should approve yourexpenditure."); System.out.print(">"); double d = Double.parseDouble(new BufferedReader(new InputStreamReader(System.in)).readLine()); manager.processRequest(new PurchaseRequest(0, d, "General")); } }catch(Exception e){ System.exit(1); }

Chain of responsibility is often applied in conjunction with Composite.

Chain of responsibility pattern vs Decorator Pattern 20

A Decorator usually wraps the decorated object: clients point to the decorator and not the object A Decorator does not have to forward the same message A decorated object does not have to know that it is wrapped With a chain of responsibility, the client asks the first chain objects explicitly. 21

In chain of responsibility: you can break the chain at any point Decorators can be thought of as executing all at once without any interaction with the other decorators Links in a chain can be thought of as executing one at a time, because they each depend on the previous link 22

Thank you 23

? 24