System Design
15. Software Design PatternsAnimated walkthrough
Composite Pattern
Treat single items and groups the same way.
The idea
A tree where leaves and containers share an interface, such as folders and files.
Watch it work
The steps light up one at a time. Use the controls to pause or step through.
- 1Define a common interface
- 2Leaves implement it
- 3Composites hold children
- 4Operations recurse
1/4
Step by step
- 1Define a common interface
- 2Leaves implement it
- 3Composites hold children
- 4Operations recurse
Where it is used
Trees and menus.
Watch out for
Overly general interfaces.