lundi 25 janvier 2016

Is there a good solution to a composite pattern, where a root element is needed, but no element can be root?

I have a structure where, executing Update(); on the root element will recursively traverse the structure and execute Update(); on all child nodes.

This works just like I want it to, however, no element seem to qualify as being the root element. It looks like this

A simplified version of the data structure

This is what I ended up doing. I created a class called GameHandlerRoot, which does nothing, except act like a root. Call Update(); on this, and everything updates. Is this viable? There must be better solutions than a fake.

To be specific, even if you could find an element that would qualify as a root, I am only interested in a solution, where no such element exists.

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire