Design Patterns and Frameworks – Structural Patterns: Summary
Oliver Haase
Oliver Haase Emfra — Structural Patterns: Summary 1/9
Magic Circle of Structural Patterns — Ok, Just Kidding...
Magic Circle of Structural Patterns — Ok, Just Kidding...
Oliver Haase Emfra — Structural Patterns: Summary 3/9
Adapter vs. Bridge
Commonalities:
I Level of Indirection for the access to the actual object
I Delegation from an interface that the actual object doesn’t provide
Adapter vs. Bridge
Differences:
I Purpose:
I Adapterintends to match an implementation with a (different) interface
I Bridgeintends to separate implementation from abstract to enable both to evolve separately
I Time of application:
I Adapteris employed rather later, i.e. when two existing types need to be brought together
I Bridgeis employed early, to foresee separate evolution of abstraction and implementation
Oliver Haase Emfra — Structural Patterns: Summary 5/9
Composite vs. Decorator
Commonalities
I Structures of composite and decorator very similar (both use recursion to structure hierarchies of objects
I Decorator structure might be mistaken for degenerated composite structure
→ composite builds tree, decorator builds chain of objects
Composite vs. Decorator
Differences are in their purpose:
I Purpose:
I Decoratorintends to add functionality to a type without changing it
→avoids expontential explosion of number of classes
I Compositeintends to treat leaves and inner nodes (container objects) of an object hierarchy homogeneously
Oliver Haase Emfra — Structural Patterns: Summary 7/9
Proxy vs. Decorator
Commonalities
I Similar structures, in both cases indirect access to actual object via upstream object
I in both cases, upstream object maintains reference to actual object (subject) and delegates requests to it
Proxy vs. Decorator
Differences are in their purpose:
I Proxy is not about adding functionality, but about avoiding direct access to the subject, for varying reasons (protection, efficiency, transparent remote access)
I With proxy pattern, proxy implements key functionality, with decorator pattern, functionality is split across levels of indirection.
Oliver Haase Emfra — Structural Patterns: Summary 9/9