Intent
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Why is this used?
This allows us to build structures of objects in the form of trees that contain both compositions of objects and individual object nodes.
Using a Composite structure, we can apply the same operations over both composites and individual objects. In other words, in most cases, we can ignore the difference between the composition of objects and individual objects.
This allows us to build structures of objects in the form of trees that contain both compositions of objects and individual object nodes.
Using a Composite structure, we can apply the same operations over both composites and individual objects. In other words, in most cases, we can ignore the difference between the composition of objects and individual objects.
UML diagram representation
https://www.codeproject.com/KB/Blogs/186192/1.jpg
https://www.codeproject.com/KB/Blogs/186192/1.jpg
Source code example
https://www.tutorialspoint.com/design_pattern/composite_pattern.htm
More to follow...