Use the Composite pattern when…


You have:

  • An irregular structure of objects and composites of the objects

You want:

  • Clients to ignore all but the essential differences between individual objects and composites of objects
  • To treat all objects in a composite uniformly

But consider using as well:

  • The Decorator pattern to provide operations like Add, Remove, and Find
  • The Flyweight pattern to share components, provided the notion of “where I am” can be disregarded and all
  • operations start at the root of the composite
  • The Visitor pattern to localize the operations that are currently distributed between the Composite and
  • Component classes