Wrapper Patterns (Proxy - Decorator - Adaptor - Bridge - Facade)
- all use composition, wrapping subject
- delegates the execution to the subject at some point
- often maps one method call to another one
- differ in intent and interface
|
Pattern |
Interface to Client |
Main Purpose |
Wraps Existing Object? |
Allows |
Designed When |
Constructor Behavior |
Examples |
|---|---|---|---|---|---|---|---|
|
Same
|
Control access to an object |
❌ (creates internally) |
❌ |
Runtime |
No subject passed in; creates object lazily |
| |
|
Same + enhanced
|
Add behavior without subclassing |
✅ |
✅ |
Runtime |
Takes existing object in constructor |
| |
|
Different
|
Make incompatible interfaces compatible |
✅ |
❌ |
After design |
Takes existing object in constructor |
| |
|
New, simplified |
Simplify complex subsystem |
✅ (object graph) |
❌ |
After design |
Takes root of complex object graph |
| |
|
Abstract |
Decouple abstraction & implementation |
✅ (abstract impl) |
❌ |
Before design |
Takes implementation abstraction |
|