• Keine Ergebnisse gefunden

Design Patterns & Refactoring Comparison of the Behavioral Patterns Oliver Haase

N/A
N/A
Protected

Academic year: 2022

Aktie "Design Patterns & Refactoring Comparison of the Behavioral Patterns Oliver Haase"

Copied!
7
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Design Patterns & Refactoring

Comparison of the Behavioral Patterns

Oliver Haase

HTWG Konstanz

(2)

Encapsulation of the Variation

Many behavioral patterns encapsulate the varying concept, clients are loosely coupled to the encapsulated concept:

behavioral pattern encapsulated concept

strategy algorithm

state state dependend behavior broker protocol between objects

iterator access to and traversal of collections

Without encapsulation, varying concept would be integrated into client object

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

(3)

Objects as Arguments

Some behavioral patterns define objects that are always used as arguments, e.g. visitor pattern → Visitoralways used as argument to accept-call of a Node.

Some patterns define object that is passed around as magic token without the clients’ knowledge of its content (Command object, Memento object).

(4)

Encapsulation or Distribution of Communication

Observer Pattern:

Communication is distributed across subjects (observables) and observers

Responsibility to preserve consistency is shared.

Communication flows at run-time are hard to understand

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

(5)

Encapsulation or Distribution of Communication

Broker Pattern:

Communication is centralized in broker (mediator) object Broker is responsible to preserve consistency

Broker is single point of failure and scalability bottle-neck Communication flows at run-time are easier to understand

(6)

Decoupling of Sender and Receiver

An object that uses another object gets dependent on it. The following patterns follow different approaches to minimize this coupling:

Command: Sender usesCommand object through a small, predefined interface, .i.e. executeoperation. Commandobject uses the receiver’s specific, possibly complex interface.

Observer: Subjects notify observers through a simplynotify operation, decoupling subjects from observers.

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

(7)

Decoupling of Sender and Receiver

Broker: Sender usesBrokerobject to communicate with receiver.

This decouples senders from receivers, but couples them to broker.

Chain of Responsibility: Client is decoupled from receivers through their internal chaining of the request.

Referenzen

ÄHNLICHE DOKUMENTE

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

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

ensure that a class can be instantiated exactly once provide global access point to single instance Application Examples:.. exactly one driver for a piece if hardware (e.g.

Implementor (CommImpl): defines interface for implementation classes (can differ from Abstraction interface). ConcreteImplementor (TcpCommunication): provides implementation

Receiver must allow command object to restore receiver’s original state. Client stores all executed commands in a

knows which subsystem classes are responsible for which requests delegates client requests to respective subsytem

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