Skip to content

The composite pattern is a partitioning design pattern. The composite pattern describes a group of objects that are treated the same way as a single instance of the same type of object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies.

License

Notifications You must be signed in to change notification settings

ParsaMehdipour/Intro-To-Composite-Design-Pattern

Repository files navigation

Intro-To-Composite-Design-Pattern

Composite is a structural design pattern that lets you compose objects into tree structures and then work with these structures as if they were individual objects. Composite became a pretty popular solution for the most problems that require building a tree structure.


  1. The Component interface describes operations that are common to both simple and complex elements of the tree.

  2. The Leaf is a basic element of a tree that doesn’t have sub-elements. Usually, leaf components end up doing most of the real work, since they don’t have anyone to delegate the work to.

  3. The Container (aka composite) is an element that has sub-elements: leaves or other containers. A container doesn’t know the concrete classes of its children. It works with all sub-elements only via the component interface. Upon receiving a request, a container delegates the work to its sub-elements, processes intermediate results and then returns the final result to the client.

  4. The Client works with all elements through the component interface. As a result, the client can work in the same way with both simple or complex elements of the tree.

About

The composite pattern is a partitioning design pattern. The composite pattern describes a group of objects that are treated the same way as a single instance of the same type of object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages