in my application I have a tree-like data structure. The nodes are of class X. I have another class Y which is derived from X. Eventually, I need to “transform/change” the nodes from type X to type Y – in the whole tree structure.
Is there an easy way to do this or do I have to parse the whole tree, recreating it by instantiate each node with type Y?
Thanks in advance,
Frank
Edith says: Thanks for all your answers! I try to explain, why I need this behavior:
Let’s imagine, we are a caterer. We want to model our portfolio in a tree. One node could be “soups” and we offer potato soups, tomato soups and noodle soups – each one is a child node of the “soups” node. After finishing the modeling, we present the tree to a customer who choses the “basic catering service”. That means that she can chose one of the soups for her dinner.
For my underlying model, that means I need an additional field “IsSelected”, which I do not need, when the caterer creates the portfolio. So I want to derive class Y from class X with the additional field.
Yes, you will have to traverse the whole tree and re-create all the nodes.
Which makes it a good idea to reconsider the design that led to this situation.