Composite Pattern


Composite Pattern

http://userpages.umbc.edu/~tarr/dp/lectures/Composite.pdf

 

Where should the child management methods (add(), remove(), getChild())
be declared?
1. In the Component class: Gives transparency, since all components can be
treated the same. But it's not safe, since clients can try to do meaningless
things to leaf components at run-time.
2. In the Composite class: Gives safety, since any attempt to perform a child
operation on a leaf component will be caught at compile-time. But we lose
transparency
, since now leaf and composite components have different
interfaces.

 

let's look at its analysis, why does it describe it as transparency, it's just interesting, perhaps it uses transparency to mean consistency?

你可能感兴趣的:(Pattern)