designpatterns/structural

It lets you build tree-like structures where both leaves (single objects) and branches (composite groups) can be interacted with using the same interface

aka Object Tree.
The Composite Pattern is a structural design pattern that allows you to treat individual objects and groups of objects (composites) the same way.

Analogy

A folder system on your computer:

  • A folder can contain files or other folders.
  • You can perform actions like delete, rename, or move on both files and folders.
  • Whether you’re dealing with one file or a whole folder of items, you treat them the same.

When to Use

  • You need to represent hierarchies of objects (like trees or folders).
  • You want uniform treatment for individual and composite objects.
  • You want to simplify client code by hiding the difference between single and group operations.