-
Book Overview & Buying
-
Table Of Contents
An Atypical ASP.NET Core 5 Design Patterns Guide
By :
The Composite design pattern is another structural GoF pattern that helps us manage complex object structures.
The goal behind the Composite pattern is to create a hierarchical data structure where you don't need to differentiate groups of elements from a single element. You could think of it as a way of building a graph or a tree with self-managing nodes.
The design is straightforward; we have components and composites. Both implement a common interface that defines the shared operations. The components are the single nodes, while the composites are collections of components. Let's take a look at a diagram:
Figure 9.7 – Composite class diagram
In the preceding diagram, Client depends on an IComponent interface. By doing so, it is unaware of the implementation it is using; it could be a Component or a Composite. Then, we have two implementations:
Component represents...