Composite Design Pattern
Get an overview of the composite design pattern.
We'll cover the following...
Overview
Let’s take a top-down approach to understanding this pattern by starting with a definition. According to the Gang of Four book, “The composite design pattern composes objects into tree structures to represent part-whole hierarchies. It lets clients treat individual objects and compositions of objects uniformly.”
Before going deeper into the definition, let’s discuss what is meant by individual objects and the composition of objects.
The composition of objects has child components, and leaf objects don’t have any child components.
For example, let’s say we have a computer system with directories and files. We can consider directories as a composition of objects because we can find files or directories or both of them inside directories. On the other ...