12.5 The Composite pattern
The Composite pattern allows complex tree structures to be built from simple components, often called nodes. A node with children will behave like a container; a node without children will behave like a single object. A composite object is — generally — a container object, where the content may be another composite object.
Traditionally, each node in a composite object must be either a leaf node (that cannot contain other objects) or a composite node. and leaf nodes can have the same interface. The following UML diagram shows this elegant parallelism as a some_action() method:
This simple pattern, however, allows us to create complex arrangements of elements, all of which satisfy the interface of the component object. Figure 12.10 (next page) depicts a concrete instance of such a complicated arrangement.