The Composite Design Pattern

The composite design pattern is used to represent hierarchies and networks.

 

Examples

The simplest example is a tree data structure (such as a binary tree or 2-3 tree). In this case parent nodes are composites while leaf nodes are primitives:

 

Here's a sample implementation:

TestTree.java

Of course nothing in this pattern prevents a child of parent p from being p's grandparent. Thus, arbitrarily complex networks or graphs can be represented by this pattern.


Organization Theory

Accountability

Affiliation


Partonomic Hierarchies

Programs as Assemblies

Graphical User Interfaces as Assemblies

Graphics Libraries