Composite pattern
is useful for handling part-whole hierarchies. It has an interface for the Component
. Leaf
and Composite
both provide implementation for the Component
interface.
What should be the implementation for Add(Component c)
, Remove(Component c)
and GetChild(int position)
methods in Leaf
class ?
I can have methods do nothing, or throw an exception like : OperationNotSuportedByLeafException
. But Doing this will break the Liskov substitution principle. What is the best way to handle these methods ?
Aucun commentaire:
Enregistrer un commentaire