pattern oriented design chain of responsibility from:design patterns gamma. johnson helm. vlissides...

18
Pattern Oriented Design Chain of Responsibility From: Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊楊楊 R9306008 楊楊楊 R9306016 楊楊楊 R9306024 楊楊楊 R9306025 楊楊楊 R9306029 楊楊楊 2004/Dec/21

Upload: marian-flowers

Post on 03-Jan-2016

240 views

Category:

Documents


14 download

TRANSCRIPT

Page 1: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

Pattern Oriented Design Chain of Responsibility

From: Design Patterns Gamma. Johnson Helm. Vlissides (GoF)Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

R9306024 陳錫樺 R9306025 葉冠良 R9306029 謝漢風 2004/Dec/21

Page 2: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

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 楊汝康

Page 3: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

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.

Page 4: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

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.

Page 5: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 5

Structure Example

if(/* 符合請求條件一 */)// 執行請求一else if(/* 符合請求條件二 */)// 執行請求二else// 執行預設請求或顯示訊息

Page 6: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

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)

Page 7: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 7

Object Diagram

The goal is avoid the coupling

Page 8: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 8

Non-software

Domian

Domian

DomainDomainDomian

Domian

DomainDomain

DomainDomain

Host A

Page 9: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 9

Interaction Diagram

Neither aPrintButtom nor aPrintDialog handles the request; it stops at anApplication, which can handle it or ignore it.

Page 10: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 10

UI Operation Example

Page 11: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 11

UI Operation Example

Page 12: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

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

Page 13: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 13

Class DiagramSuper class

Page 14: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 14

Structure

Handler HelpHandler

ConcreteHandler PrintButtom, PrintDailog

Client

Page 15: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

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.

Page 16: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

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

Page 17: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 17

Consequences of Behavior Patterns Separate the sender receiver

Command Observer Mediator Chain of Responsibility

Page 18: Pattern Oriented Design Chain of Responsibility From:Design Patterns Gamma. Johnson Helm. Vlissides (GoF) Present: F8906082 楊汝康 R9306008 徐德皓 R9306016 高稚翔

2004/Dec/21 18

End

Any questions?