| layout | pattern | |||
|---|---|---|---|---|
| title | Composite | |||
| folder | composite | |||
| permalink | /patterns/composite/ | |||
| categories | Structural | |||
| tags |
|
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
In plain words
Composite pattern lets clients treat the individual objects in a uniform manner.
Wikipedia says
In software engineering, the composite pattern is a partitioning design pattern. The composite pattern describes that a group of objects is to be treated in the same way as a single instance of an object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects and compositions uniformly.
Use the Composite pattern when
- you want to represent part-whole hierarchies of objects
- you want clients to be able to ignore the difference between compositions of objects and individual objects. Clients will treat all objects in the composite structure uniformly
- java.awt.Container and java.awt.Component
- Apache Wicket component tree, see Component and MarkupContainer

