Please enable JavaScript.
Coggle requires JavaScript to display documents.
Composite Pattern - Coggle Diagram
Composite Pattern
Definition
Composite is a structural pattern
It let's us represent objects in a tree like structure
It allows us to represent herarchies
Let's us treat indivual objects and composites equally
Examples
shapes --graphics from wikipedai
management system -- geeksforgeeks
products and boxes -- refactoring guru
song playlists
Solutions that composite pattern give
define a component interface for both indivudla objects and composite
leaf objects implement the component directly and composite allows client to directly access them
clients work with leafs directly and composite simply passses instruction down to leafs recursively making it easier to work, debug, and test
Problemse that composite pattern solve
when clients wnat to represetn heirarchy and indivudal objects equally
when herarchy need to represented in tree like structure
why would you want to do that?
benefits
you can work with tree like structures more effectivaly
you can easily introduce new elements
when to use?
when clients see that they are treating objects and composites the same way.
downsides
overgenerlazation