| id | structural/composite | |||||
|---|---|---|---|---|---|---|
| name | Composite | |||||
| aliases |
|
|||||
| guide_url | https://python-patterns.guide/gang-of-four/composite/ | |||||
| problem | Let callers treat a single object and a whole tree of objects through one interface. | |||||
| symptoms |
|
|||||
| verdict | pythonic | |||||
| caveats |
|
|||||
| stdlib_sightings |
|
Part-whole trees where a leaf and a whole subtree answer the same operation — and only containers manage children. Verdict: pythonic — the right shape for trees; keep the leaf's interface honest.
| Where | What |
|---|---|
pattern/ |
The importable code: Composite, HasTotal |
docs/ |
Fundamentals · Implementation guide · External examples |
examples/org_chart/ |
Mini-project: headcount/cost rollups over a nested org chart |
tests/ |
Behavioral tests for the pattern and the mini-project |
uv run python -m patterns.structural.composite.examples.org_chart.main