Intent - Compose objects into tree structures to
represent part-whole hierarchies. Composite lets clients
treat individual objects and compositions uniformly
Problem -
Objects need to be treated the same whether they are a
single object or a group of objects.
Clients should be able to treat whole objects or
groups of objects the same, without knowing (or
needing to know) the difference.
Solution - Use a command abstract class for both
the groups and the individual objects
Participants and Collaborators
Component - (Test)
Leaf - (TestCase)
Composite - (TestSuite)
Client - (TestRunner)
Consequences
Defines class heirarchies consisting of primitive
objects and composite objects. Client code that
expects a primitive object can alo take a composite.
The client is simple. No if-else, case-statements
needed to handle the Composite.
New Components can be added easily. They work
automatically with existing clients.
The design can be made overly general. It can be too
hard to restrict the components of the composite.
Run-time checks of the type will be needed to
constrain the components.