Composite Pattern
The Composite Design Pattern is a structural design pattern of Object-Oriented Programming (OOP) that lets you compose objects into tree structures and then work with these structures as if they were individual objects.
It helps when you want to treat a group of objects and a single object in the same way. It is particularly useful in designing hierarchical structures such as file systems, GUI components, or organizational hierarchies.
Participants in the pattern:
Component: This abstract class/interface declares the interface for objects in the composition and implements default behavior for the interface common to all classes, as appropriate. It also declares an interface for accessing and managing its child components.
Leaf: This class represents leaf objects in the composition. A leaf has no children and defines behavior for primitive objects in the composition.
Composite: This class defines behavior for components having children and stores child components. It implements child-related operations in the Component interface.