Purpose:
Compose objects into tree structures to represent part-whole
hierarchies. Composite lets clients treat individual objects and
compostions of objects uniformly.
Structure:
The composite object contains other primitive objects(or say
Components), and has the same operation as in those primitive objects.
Thus we can operater the composite object with the same operations as a
whole. Or in other word, composite object is a container of primitive
ojects and itself is derived from same base (abstract) class as
primitives, so that it can have same operations as primitives.
Actually, we can say that the abstract class represents both primitives
and their containers
Implementation:
-- Extend a base class that represents primitive objects. And the same
operation(override function) will be implemented by iterating over that
collection and invoking the appropriate method for each component in
the collection.
-- Add & Remove function (for component collection) will be defined
in base class, though it is meaninglessful for leaf classes.
reference:
http://www.javaworld.com/javaworld/jw-09-2002/jw-0913-designpatterns.html
http://www.codeproject.com/useritems/Composite.asp
example:
http://java.sun.com/blueprints/patterns/CompositeView.html