• Keine Ergebnisse gefunden

Design Patterns & Refactoring Comparison of the Structural Patterns Oliver Haase

N/A
N/A
Protected

Academic year: 2022

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

Copied!
9
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Design Patterns & Refactoring

Comparison of the Structural Patterns

Oliver Haase

HTWG Konstanz

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

(2)

Magic Circle of Structural Patterns — Ok, Just Kidding...

(3)

Magic Circle of Structural Patterns — Ok, Just Kidding...

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

(4)

Adapter vs. Bridge

Commonalities:

Level of Indirection for the access to the actual object

Delegation from an interface that the actual object doesn’t provide

(5)

Adapter vs. Bridge

Differences:

Purpose:

Adapterintends to match an implementation with a (different) interface

Bridgeintends to separate implementation from abstract to enable both to evolve separately

Time of application:

Adapteris employed rather later, i.e. when two existing types need to be brought together

Bridgeis employed early, to foresee separate evolution of abstraction and implementation

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

(6)

Composite vs. Decorator

Commonalities

Structures of composite and decorator very similar (both use recursion to structure hierarchies of objects

Decorator structure might be mistaken for degenerated composite structure

→ composite builds tree, decorator builds chain of objects

(7)

Composite vs. Decorator

Differences are in their purpose:

Purpose:

Decoratorintends to add functionality to a type without changing it

avoids expontential explosion of number of classes

Compositeintends to treat leaves and inner nodes (container objects) of an object hierarchy homogeneously

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

(8)

Proxy vs. Decorator

Commonalities

Similar structures, in both cases indirect access to actual object via upstream object

in both cases, upstream object maintains reference to actual object (subject) and delegates requests to it

(9)

Proxy vs. Decorator

Differences are in their purpose:

Proxyis not about adding functionality, but about avoiding direct access to the subject, for varying reasons (protection, efficiency, transparent remote access)

With proxy pattern, proxy implements key functionality, with decorator pattern, functionality is split across levels of indirection.

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

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..

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

Oliver Haase (HTWG Konstanz) Design Patterns and Refactoring 1 /

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

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