The Composite design pattern helps us deal with a type of object – individually or as a group. In other words, our codes should be able to process that object alone. Also, our codes can deal with a collection of that type of object. While dealing with an entity is easy, dealing with a group of collections of objects is not. These collections could be in various structures like lists or trees.
The Basic Idea Of The Pattern
The basic idea of the pattern is to treat an object of a certain type and a group thereof the same. Therefore, for example, our codes can display the content of an object. Also, they can display the content of a collection of objects.
The Composite Pattern Off The Gang of Four
What does the Gang of Four tell about the Composite design pattern?
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
The first statement refers to a group or collection of objects that may be in a certain structure, e.g., a tree. That grouping composes of objects or groups of collections of objects. As a whole, we treat them the same as we would on each of its member items.
Other Design Patterns
The Composite design pattern is only one of the structural design patterns for creating maintainable software applications. Other design patterns are available on Design Patterns Are The Ultimate Toolkit For Programmers.