Structural patterns
How to assemble classes and objects into larger structures that stay flexible.
- 7patterns
- 47animated steps
- 42code examples
Structural patterns describe how to compose objects to gain new capabilities without changing existing classes: adapting an interface, adding behavior, simplifying a subsystem.
The patterns
- 6Adapter
Let objects with incompatible interfaces work together, through a translator.
- 7Bridge
Decouple an abstraction from its implementation so that the two can evolve independently.
- 8Composite
Compose objects into tree structures and treat leaves and groups uniformly.
- 9Decorator
Add behavior to an object dynamically by wrapping it in objects that share its interface.
- 10Facade
Provide a simplified interface to a complex set of classes, libraries or subsystems.
- 11Flyweight
Save memory by sharing the common (intrinsic) state across a large number of objects.
- 12Proxy
Provide a stand-in that controls access to an object: caching, lazy loading, security, loggingโฆ
At a glance
| Pattern | Also known as | Use it for |
|---|---|---|
| Adapter | Wrapper | Integrate a third-party library / API |
| Bridge | Handle/Body | Two independent dimensions of variation |
| Composite | โ | Tree structures: files, menus, DOM, org charts |
| Decorator | Wrapper | Adding responsibilities without modifying the class |
| Facade | โ | Simplifying the use of a complex subsystem |
| Flyweight | โ | Very large numbers of similar objects |
| Proxy | Surrogate | Caching / memoization |
Other families
-
Creational patterns
5 patterns
How to create objects flexibly, without coupling your code to concrete classes.
-
Behavioral patterns
11 patterns
How objects communicate and share responsibilities.