Structural Patterns — Notes#
Quick chooser#
| You want to... | Pick |
|---|---|
| Use a class with the wrong interface | Adapter |
| Add behaviour to one instance without subclassing | Decorator |
| Hide a complex subsystem | Facade |
| Control access / cache / log calls | Proxy |
| Treat individuals and groups uniformly | Composite |
| Decouple abstraction from implementation | Bridge |
| Reduce memory of many similar small objects | Flyweight |
Adapter vs Bridge#
Adapter is reactive — bridges an existing incompatibility. Bridge is proactive — designed in advance so abstraction and implementation can evolve separately.
Decorator vs Proxy#
- Decorator adds behaviour, often visible (e.g. logging).
- Proxy controls or replaces access, often transparent (caller can't tell it's there).
Facade vs API gateway#
The API Gateway is a Facade applied at the service-mesh level.
Refs#
- GoF book chapters on structural patterns.
- Java
java.iopackage — half of it is decorators + adapters. - Spring AOP — Proxy at runtime, code-generated.