Composite pattern

E680644

The Composite pattern is a structural design pattern that lets you treat individual objects and compositions of objects uniformly by organizing them into tree-like hierarchies.

Jump to: Statements Referenced by

Statements (48)

Predicate Object
instanceOf software design pattern
advantage makes it easy to add new kinds of components
promotes transparency between leaf and composite objects
simplifies client code by providing a uniform interface
supports recursive structures
applicableWhen you want clients to ignore the difference between individual objects and compositions
you want to represent part-whole hierarchies of objects
belongsTo Gang of Four design patterns NERFINISHED
canBeImplementedIn C# NERFINISHED
C++ NERFINISHED
Java NERFINISHED
Python NERFINISHED
ClientRoleResponsibility manipulates objects in the composition through the Component interface
ComponentRoleResponsibility declares interface for accessing and managing child components
declares interface for objects in the composition
implements default behavior for common interface operations
CompositeRoleResponsibility defines behavior for components having children
implements child-related operations such as add and remove
stores child components
definesRole Client
Component
Composite
Leaf
describedIn Design Patterns: Elements of Reusable Object-Oriented Software NERFINISHED
disadvantage can make it harder to restrict the components of a composite
can make the design overly general
encourages use of polymorphism over explicit type checks
firstPublishedYear 1994
hasAlias Object tree pattern
hasIntent allow clients to treat individual objects and compositions uniformly
compose objects into tree structures to represent part-whole hierarchies
LeafRoleResponsibility defines behavior for primitive objects
represents leaf objects in the composition
oftenUsedIn document object models
file system directory and file representations
graphical user interface component hierarchies
scene graphs in graphics engines
originatedFrom object-oriented design community
relatedTo Decorator pattern NERFINISHED
Flyweight pattern NERFINISHED
Iterator pattern NERFINISHED
Visitor pattern NERFINISHED
supports part-whole hierarchy modeling
recursive composition of objects
uniform treatment of leaf and composite objects
supportsOperationStyle operations defined at Component and implemented recursively by Composite
typicalOperationExample operation that traverses children and aggregates results
usesStructure tree

Referenced by (4)

Full triples — surface form annotated when it differs from this entity's canonical label.

Visitor collaboratesWith Composite pattern
Chain of Responsibility relatedTo Composite pattern
Interpreter relatedTo Composite pattern
Visitor relatedTo Composite pattern