> For the complete documentation index, see [llms.txt](https://javascript-1.gitbook.io/design-pattern/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascript-1.gitbook.io/design-pattern/structural-design-patterns/composite.md).

# Composite

A tree structure of simple and composite objects.

* Composite pattern allows you to have a tree structure and ask each node in a tree structure to perform a task.
* creates a tree structure of group of object.
* It is used where we need to treat a group of objects in similar way as a single object.
* composes objects in in term of tree structure to represent part-hole hierarchy.
* This tree is constructed with leaf (no children - represents leaf) and composite (has collection of child components - represents branch).
* Most frequently used in JavaScript.

![Part-Hole Hierarchy](https://1698315463-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LiuzoHqHr4MUK1nJBO8%2F-Lpq8j_Z2JGorKm1GbAU%2F-LpqJsBvyCuSHCqEctBQ%2Fimage.png?alt=media\&token=e1a22210-04db-4be9-b8e0-51b69d8e7b4e)
