mercredi 27 novembre 2019

Composite Pattern: Is the root a simple Composite?

To implement the Composite pattern in Java I have an abstract class Component with the functions getChild(int i), add(Component c), remove(Component c), forAllDo() and getChildren().

It is implemented by the two classes Leaf and Composite.

Leaf throws for nearly every function an exception - only forforAllDo() something is done with it. How would you implement the Root? I would understand it as a normal Composite class - all the functions make the same sense. Have you any arguments that that is not the case?

Aucun commentaire:

Enregistrer un commentaire