The Composite Pattern

archetype Architecture and BuildingObject-Oriented Design

Categories: software-engineering

What It Brings

Call a part-whole hierarchy a “composite” and you invoke the physical logic of assembled structures — buildings made of floors made of rooms, walls made of bricks, boxes packed inside boxes. The GoF Composite pattern maps this onto software: a tree structure where individual objects and compositions of objects are treated uniformly through a shared interface.

Key structural parallels:

Where It Breaks

Expressions

Origin Story

The Composite pattern was codified in Design Patterns (1994) by the Gang of Four. Its intellectual roots trace to two sources. First, Lisp’s treatment of lists and atoms through a uniform car/cdr interface (1958 onward) — the oldest part-whole uniformity in computing. Second, graphical user interface toolkits of the 1980s, particularly Smalltalk’s MVC framework and InterViews (a C++ GUI toolkit where Vlissides and Linton used composite structures for graphical objects). The pattern also owes a debt to Christopher Alexander’s architectural insight that buildings are compositions of compositions, though the GoF made the recursion mechanically precise in a way Alexander’s pattern language did not.

The name “Composite” is notably less evocative than “Factory” or “Observer” — it’s a technical term from materials science (composite materials) and mathematics (composite functions) that happens to also describe physical assembly. This multi-source etymology gives the word its quiet versatility: it doesn’t commit to a single source domain, which may be why the pattern is one of the most widely applied yet least discussed in terms of its metaphorical content.

References

Related Mappings