A Gang of Four structural design pattern that composes objects into tree structures to represent part-whole hierarchies, letting client code treat an individual object and a composite group of objects through the same interface.
Facts
Core PrincipleComposes objects into tree structures representing part-whole hierarchies so a client can treat an individual object and a composition of objects uniformly. 2 Connections
Associated With
Erich Gamma, Pioneers Erich Gamma co-authored the 1994 Design Patterns book that named and catalogued the Composite pattern among the original 23.
In Field
Sources
1. Wikipedia: Design Patterns (book)
Wikimedia FoundationLead section, first sentenceQuote, Lead section, first sentence
Design Patterns: Elements of Reusable Object-Oriented Software (1994) is a software engineering book describing software design patterns.
View the Source 2. Wikipedia: Composite Pattern
Wikimedia FoundationOverview sectionQuote, Overview section
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.
View the Source Frequently Asked Questions
When should the Composite pattern be used?
Use it when client code treats a single object and a group of objects the same way.
The Composite pattern is the right choice when client code would otherwise have to treat individual objects and groups of objects differently even though it handles them almost the same way. Composite should be used when clients ignore the difference between compositions of objects and individual objects, so if a program is repeating nearly identical handling code for a single object and for a group of them, folding both into one Component interface removes that duplication and treats primitives and composites as one homogeneous group.
Reader Challenges (0)
No disputes yet. Spotted an error or a better source? Open the first one.
Sign in to dispute this or suggest a correction.