The Composite Pattern, also known as the part-whole pattern, is used to treat a group of similar objects as a single object. It is usually based on a tree structure to combine objects, representing both part and whole hierarchy. This type of design pattern belongs to the structural pattern, which creates a tree-like structure of object groups.
In software engineering, the composite pattern is a partitioning design pattern that describes treating a group of objects in the same way as a single instance of an object. The purpose of composition is to structure objects into a tree hierarchy to represent the entire structure of the part. In other words, it combines objects into a tree structure to represent the part-whole hierarchy, providing uniform usage of individual objects and composite objects, commonly used in managing tree menus, files, folders, and forms.
It is impossible to distinguish the interface of leaf objects, only discernible at runtime.
Excessive creation of wrapper objects leads to additional memory burden.
When using the composite pattern, the declarations of leaf and branch are implemented classes instead of interfaces, violating the Dependency Inversion Principle.