Advantages
(+)
-
Simplifies clients.
-
Clients
can treat all objects in the hierarchy uniformly,
which greatly simplifies client code.
-
Makes adding new components easy.
-
Clients refer to the common
Component interface
and are independent of its implementation.
-
That means, clients do not have to be changed when new
Composite or Leaf classes are added
or existing ones are extended.
-
Allows building and changing complex hierarchies
dynamically at run-time.
-
The pattern shows how to apply
recursive composition
to build complex hierarchical
object structures
dynamically at run-time.
Disadvantages
(–)
-
Uniformity versus type safety.
-
There are two main design variants
to implement
child-related operations:
design for uniformity
and design for type safety
(see Implementation).
-
The Composite pattern emphasizes uniformity over type safety.