Applicability:

Typical situations in which the composite pattern can be applied in software design include representing part-whole hierarchies of objects and those when it should be possible to treat all objects in the composite structure uniformly by a client.

Consequences:

Using the composite pattern lets designers define hierarchies consisting of both primitive and composite entities, makes the client simple, also makes it easier to add new kinds of components, but can make the design overly general because it is hard to restrict the components in such a design.

Implementation:

These are many things to consider when implementing the composite pattern. It is related to child to parent referances in a composite structure. Maintaining such referances can make the design much more efficient, since it simplifies traversal and management of the composite structure. For example, having appropriate referances from graphics objects to topics of a lesson is essential, especially when a graphics object can be presented during more than one topic presentation.

Known Uses:

Almost every user interface toolkit uses composite for representing complex screen objects containing text, graphics, images, and other elements.

Related patterns

composite is often used with the patterns called chain of responsibility, iterator, and decorator.