Intent

Build a complex object using simple objects.

Where to use & benefits

Structure


Participants

Component  (IShapeContainer)
It provide the interface for for accessing and managing its child components and implements default behavior which are common to all concreate classes.

Leaf  (IShape)
It represents an objects in the composition which can't compose other objects.

Composite  (ShapeContainer)
It store other componets defines behavior for for them.

Client  (MainApplet)
It manipulates objects in the composition through the Component interface.

Example

In the demonstration application, the composite pattern is partially implemented due to the UI constraints. The ShapeContainer class is composed of shape (IShape) objects.

Class Diagram


Source Code Links