Upload
marian-flowers
View
232
Download
14
Tags:
Embed Size (px)
Citation preview
Pattern Oriented Design Chain of Responsibility
From: Design Patterns Gamma. Johnson Helm. Vlissides (GoF)Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔
R9306024 陳錫樺 R9306025 葉冠良 R9306029 謝漢風 2004/Dec/21
2004/Dec/21 2
Outline
Introduction 高稚翔 Structure Example 高稚翔 Object Example 葉冠良 Object Diagram 葉冠良 Non-software 葉冠良 UI Operation Example 陳錫樺 Interaction Diagram 陳錫樺 Successor 謝漢風 Class Diagram 謝漢風 Structure 徐德皓 Collaborations 徐德皓 Consequences of Behavior Patterns 楊汝康
2004/Dec/21 3
Introduction
3 majors 1.Creational Patterns
Abstract factory 、 builder…. Etc. 2.Structural Patterns
adapter 、 facade 、 proxy…etc. 3.Behavioral Patterns
Chain of responsibility 、 command 、 memento…etc.
2004/Dec/21 4
Introduction
Chain of Responsibility Avoid coupling the sender of a request to its
receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
2004/Dec/21 5
Structure Example
if(/* 符合請求條件一 */)// 執行請求一else if(/* 符合請求條件二 */)// 執行請求二else// 執行預設請求或顯示訊息
2004/Dec/21 6
Object Example
Consider a context-sensitive help facility for a graphical user interface. The user can obtain help information on any part of the interface just by clicking on it(F1)
2004/Dec/21 7
Object Diagram
The goal is avoid the coupling
2004/Dec/21 8
Non-software
Domian
Domian
DomainDomainDomian
Domian
DomainDomain
DomainDomain
Host A
2004/Dec/21 9
Interaction Diagram
Neither aPrintButtom nor aPrintDialog handles the request; it stops at anApplication, which can handle it or ignore it.
2004/Dec/21 10
UI Operation Example
2004/Dec/21 11
UI Operation Example
2004/Dec/21 12
Successor
To forward the request along the chain, and to ensure receivers remain implicit, each object on the chain shares a common interface for handling requests and for accessing its successor on the chain
1 2 3
2004/Dec/21 13
Class DiagramSuper class
2004/Dec/21 14
Structure
Handler HelpHandler
ConcreteHandler PrintButtom, PrintDailog
Client
2004/Dec/21 15
Collaborations
When a client issues a request, the request propagates along the chain until a ConcreteHandler object takes responsibility for handling it.
2004/Dec/21 16
Consequences
Has the following benefits and liabilities Advantage
Reduced coupling. Added flexibility in assigning responsibility to objects
disadvantage Receipt isn’t guaranteed
2004/Dec/21 17
Consequences of Behavior Patterns Separate the sender receiver
Command Observer Mediator Chain of Responsibility
2004/Dec/21 18
End
Any questions?