Composite
Implementation
There are many issues to consider when implementing the Composite pattern:
-
-
-
-
- Should Component implement a list of Components?
You might be tempted to define the set of children as an instance
variable in the Component class where the child access and management
operations are declared. But putting the child pointer in the base
class incurs a space penalty for every leaf, even though a leaf never
has children. This is worthwhile only if there are relatively few
children in the structure.