Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
"Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly." (Gamma, E., R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Reading, MA: Addison-Wesley, 1995)
Graphics applications like drawing editors and schematic capture systems let users build complex diagrams out of simple components. The user can group components to form larger components, which in turn can be grouped to form still larger components. The key to the Composite pattern is an abstract class that represents both primitives and their containers. For the graphics system, this class is Graphic (Component in the thumbnail). Graphic declares operations like Draw (Operation in thumbnail) that are specific to graphical objects. It also declares operations that all composite objects share, such as operations for accessing and managing its children. Subclasses Line, Rectangle, and Text (Leaf in thumbnail) define primitive graphical objects. These classes implement Draw to draw lines, rectangles, and text, respectively. Since primitive graphics have no child graphics, none of these subclasses implements child-related operations. The Picture class (Composite in thumbnail) defines an aggregate of Graphic objects. Picture implements Draw to call Draw on its children, and it implements child-related operations accordingly. Because the Picture interface conforms to the graphic interface, Picture objects can compose other Pictures recursively.
This pattern has been used on the following systems: Almost all object-oriented systems use this pattern. The original View class of Smalltalk Model/View/Controller used it as well as almost all user interface toolkits or frameworks, for example, ET++ (used in Vobjects) and InterViews (used in Styles, Graphics, and Glyphs). RTL Smalltalk compiler framework uses this pattern extensively. RTLExpression, a Component class for parse trees, has subclasses (i.e. BinaryExpression) that contain child RTLExpression objects. These classes define a composite structure for parse trees. RegisterTransfer is the Component class for a programs intermediate Single Static Assignment form. Also, RegisterTransferSet is a Composite class for representing assignments that change several registers at once. (Johnson, R.E., C. McConnell, J.M. Lake. The RTL system: A framework for code optimization. In Rogert Giegerich and Susan L. Graham, editors, Code Generation-Concepts, Tools, Techniques. Proceedings of the International Workshop on Code Generation, pp. 255-274, Dagstuhl, Germany, 1992. Springer-Verlag.) This pattern also occurs in the financial domain, where a portfolio aggregates individual assets. Complex aggregations of assets can be supported by implementing a portfolio as a Composite that conforms to the interface of an individual asset. (Birrer, A. and T. Eggenschwiler. Frameworks in the financial engineering domain: An experience report. In European Conference on Object-Oriented Programming, pp. 21-35, Kaiserslautern, Germany, July 1993. Springer-Verlag.)
Chain of Responsibility, Decorator, Flyweight, Iterator, and Visitor patterns

Composite pattern, Decorator pattern, Flyweight pattern, Chain of Responsibility pattern, Iterator pattern, Visitor pattern, structural patterns, Gamma patterns, uniformly treated objects, recursive composition, tree structure, part-whole hierarchies, explicit parent references
any system with large number of whole-part object relationships
need to protect clients from knowing if an object is a whole or a part
simplifies adding new parts in whole-part relationshipssimplifies the client - permitting the client to treat whole or part objects generically
may make the design too general by minimizing type safety
Test driver Test.javaSimple implementation of the pattern - Leaf class. Leaf.javaSimple implementation of the pattern - Composite class. Composite.javaSimple implementation of the pattern - Component class. Component.javaTest driver testcomposite.cppSimple implementation of the pattern. composite.h