Composite pattern

The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies.

This makes client classes easier to implement, change, test, and reuse.

When dealing with Tree-structured data, programmers often have to discriminate between a leaf-node and a branch.

The operations you can perform on all the composite objects often have a least common denominator relationship.

Instead, the Client refers to the common Component interface and can treat Leaf and Composite uniformly.

The Leaf class has no children and implements the Component interface directly.

A sample UML class and object diagram for the Composite design pattern. [ 5 ]
Defining child-related operations in the Composite design pattern. [ 6 ]
Composite pattern in UML .
Composite pattern in LePUS3 .