Design Patterns in the VCL -- Panel as Composite
Revealing the Magician's Secrets
- Component Palette ==> Prototype
- Panel ==> Composite
- Problem
- How do I allow the client to construct arbitrarily-complex
hierarchies of my classes, while allowing uniform navigation
through the hierarchy?
- Solution
- Composite permits a design in which the container nodes implement
the same abstract class as the non-containers.
- Consequences
-
- The client can treat containers as non-containers, because containers inherit the same interface.
- The variant of Composite used by the VCL actually
pushes the "knowing about children" logic up into
the base class (TComponent) to allow even simpler
and more homogenous navigation.
N.B. this simplicity has a cost: it requires all components to share the overhead of parenthood.