design patterns & refactoring - hochschule konstanzhaase/lehre/thisterm/pare/... · oliver...

Post on 12-Aug-2020

6 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Design Patterns & RefactoringComparison of the Structural Patterns

Oliver Haase

HTWG Konstanz

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

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

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

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

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

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

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

Adapter vs. Bridge

Differences:

Purpose:

Adapter intends to match an implementation with a (different)interfaceBridge intends to separate implementation from abstract to enableboth to evolve separately

Time of application:

Adapter is employed rather later, i.e. when two existing types need tobe brought togetherBridge is employed early, to foresee separate evolution of abstractionand implementation

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

Composite vs. Decorator

Commonalities

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

Decorator structure might be mistaken for degenerated compositestructure→ composite builds tree, decorator builds chain of objects

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

Composite vs. Decorator

Differences are in their purpose:

Purpose:

Decorator intends to add functionality to a type without changing it→ avoids expontential explosion of number of classesComposite intends to treat leaves and inner nodes (container objects)of an object hierarchy homogeneously

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

Proxy vs. Decorator

Commonalities

Similar structures, in both cases indirect access to actual object viaupstream object

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

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

Proxy vs. Decorator

Differences are in their purpose:

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

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

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

top related