• Keine Ergebnisse gefunden

Design Patterns & Refactoring Chain of Responsibility Oliver Haase

N/A
N/A
Protected

Academic year: 2022

Aktie "Design Patterns & Refactoring Chain of Responsibility Oliver Haase"

Copied!
9
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Design Patterns & Refactoring

Chain of Responsibility

Oliver Haase

HTWG Konstanz

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 1 / 9

(2)

Description

Classification: Object-based behavioral pattern

Purpose: Build a chain of possible receivers of a request. Delegate request along the chain until one receiver handles it.

(3)

Motivation

Imagine a context-sensitive help system for a GUI

Each graphical component may (or may not) have associated with it a help text.

On, e.g., right mouse click, the most specific help text of the clicked-on component is displayed to the user.

aPrintButton aMouseListener

handleHelpReq

aPrintDialog

handleHelpReq

aTopLevelContainer

handleHelpReq

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 3 / 9

(4)

Idea

Chain-up potential receivers in descending order from most specific to least specific

Upon reques, each receiver can decide to handle it ot to propagate it to its successor.

(5)

Description

Applicability: Use the chain-of-responsibility pattern if

several objects could handle a request, and it is unknown at development time which one actually will.

the set of possible receivers is to be configured dynamically

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 5 / 9

(6)

Structure

Client

+ handleRequest() Handler

+ handleRequest() ConcreteHandler1

+ handleRequest() ConcreteHandler2

successor

(7)

Consequences

Loose Coupling: the chain-of-responsibility pattern decouples the sender of a request from the receiver.

No Processing Guarantee: Because each receiver may decide notto handle a request, it might fall off the chain unprocessed.

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 7 / 9

(8)

Implementation

The successor chain can

either use a pre-existing linkage of the receiver objects, or be built separately.

(9)

Related Patterns

Composite:

Often, the parent object of a composite is used as the successor object for a chain of responsibility.

Oliver Haase (HTWG Konstanz) Design Patterns & Refactoring 9 / 9

Referenzen

ÄHNLICHE DOKUMENTE

Assume, a framework defines a base class (interface) that the specific custom class has to extend (implement), in order to be used in place of the base class (interface).. The

 Programm kann direkt auf jede Zielmaschine portiert werden, die einen Interpretierer für die Sprache

Lesen Sie die Zahlen a und b von der Tastatur ein, weisen Sie das Ergebnis der obigen Berechnung einer boolschen Variablen istTeiler zu und geben Sie den Wert dieser Variablen auf

A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior..

Communication is centralized in broker (mediator) object Broker is responsible to preserve consistency. Broker is single point of failure and scalability bottle-neck Communication

plain text documents, even though its functionality is applicable to other document types as well;. Difficult to use document mock-up

Divide object state into intrinsic and extrinsic state, such that there is only a small number of distinct objects with different intrinsic states.. Share these

Element: defines an accept operation with a Visitor as argument ConcreteElement: implements the accept operation, usually by calling the visitor’s appropriate visit