gof-composite
Installation
SKILL.md
One-line summary
Compose objects into tree structures to represent part-whole hierarchies, letting clients treat individual objects (leaves) and compositions of objects (branches) uniformly.
When to use this skill
- A part-whole hierarchy: file system (files and directories), menus and submenus, GUI components (button vs panel of components), organizational hierarchies.
- Client code needs to call the same operations on both leaves and branches and not care which it has.
- Recursive structures where the recursion shouldn't show in the calling code.
When NOT to use this skill
- A flat collection — there's no hierarchy, just use a list.
- The operations are genuinely different for leaves vs. branches and forcing them through one interface awkwardly buries the distinction.
- Two-level structures with only one layer of grouping — sometimes a
List<Item>is enough without inventing a Composite.
Core content
The pattern introduces a common interface (Component) shared by leaves and composites. Both implement the operations the client cares about; composites implement them by delegating to their children.