![Spring 5 Design Patterns](https://wfqqreader-1252317822.image.myqcloud.com/cover/646/36700646/b_36700646.jpg)
Composite design pattern
-GoF Design Patterns
In software engineering, the composite pattern comes under the structural design pattern. According to this pattern, a group of objects of the same type are treated as a single object by the client. The idea behind the Composite design pattern is to compose a set of objects into a tree structure to represent a module of a larger structural application. And this structure for clients is a single unit or instance uniformly.
The motivation behind the Composite design pattern is that objects in the system are grouped into the tree structure, and a tree structure is a combination of the node-leaf and branches. In the tree structure, nodes have a number of leaves and other nodes. Leaf doesn't have anything, which means there is no child of leaf in the tree. Leaf is treated as the end point of tree-structured data.
Let's look at the following figure, which represents data in the tree structure in the form of node and leaf:
![](https://epubservercos.yuewen.com/5098A3/19470402901614006/epubprivate/OEBPS/Images/31cc8e59-1456-460a-980b-8e1c4547f63b.png?sign=1738870440-VddctBnVMadIDk0v5uWaTjWOWBsfsyuh-0-358e9f1b378a489f8ffdc86dd23bad22)