I’ve a simple Design question and am not really sure about pro´s and con´s. If I have to store data in a – lets say – tree structure. Lets say this tree and corresponding tree is a typed class (hopefully the right term).
Well, lets now say I’ve to store some data in this basic structure. For example an integer, a float and any class member variable.
Is it more logical to
- store all these values in an own class (containerlike) and use this container class
as node’s type or - to extend this node class, add additional members
and use one of these values as type?
Its a design question but probably you’ve already made acquaintance with this case.
Thanks a lot!
I would go for option 1.
Using this own class as node’s type through Generics. This would make your tree/node generic for any type of object that you could use as node.
Extending the node class would represent your object as being a node in all its uses which is probably not what you want. Plus you would probably ever use any of the node class’ methods in your own class.