Composite Pattern
Overview
Compose objects into tree structures to represent part-whole hierarchies.
Composite lets clients treat individual objects and compositions of objects
uniformly.
Participants
- declares the interface for objects in the composition.
- implements default behavior for the interface common to all classes, as appropriate.
- declares an interface for accessing and managing its child components.
- (optional) defines an interface for accessing a component's parent in the
recursive structure, and implements it if that's appropriate.
- this participant can not be an interface.
- represents leaf objects in the composition. A leaf has no children.
- defines behavior for primitive objects in the composition.
- this participant can not be read-only.
- this participant can not be an interface.
- defines behavior for components having children.
- stores child component.
- implements child-related operations in the component interface.
- this participant can not be read-only.
- this participant can not be an interface.
Parameters
-
here you can specify the name of the Composite's Vector attribute, used to keep
references to the Component objects, contained within the Composite.
-
here you can specify the name of the Composite's method for returning an
enumeration of Component objects, contained within the Composite.
-
when selected, will create special JavaDoc links in the code between pattern participants, describing
their relationships.
Applicability
Use the Composite when
- you want to represent part-whole hierarchies of objects.
- you want clients to be able to ignore the difference between compositions of objects and
individual objects. Clients will treat all objects in the composite structure uniformly.