composes objects in term of a tree structure to represent part as well as whole hierarchy
- CEO - Sales Manager - Sales Staff A - Sales Staff B - Technical Manager - Engineer A - Engineer B
The Composite Pattern has four participants:
Component declares the interface for objects in the composition and for accessing and managing its child components. It also implements default behavior for the interface common to all classes as appropriate.
Leaf defines behavior for primitive objects in the composition. It represents leaf objects in the composition.
Composite stores child components and implements child related operations in the component interface.
Client manipulates the objects in the composition through the component interface. Client use the component class interface to interact with objects in the composition structure. If recipient is a leaf then request is handled directly. If recipient is a composite, then it usually forwards request to its child components, possibly performing additional operations before and after forwarding.