views:

96

answers:

1

I am building code for a 2D scene graph and i have a single abstract class, Node that will be used to indicate that a type of item can be used in a scene graph. However, classes that implement from this are of different types such as leaf nodes and transformation nodes. How would i indicate these differences? would i use attributes, other interfaces, or what?

Edit: It would appear that i have given insufficient information. Here is as much information as i can provide on my current hierarchy:

  • INode interface
    • requires a Matrix called TransformationMatrix
    • requires a List of INodes called Children
    • requires a Node called Parent
    • requires that a method be implemented called Draw which takes one Matrix as an argument and returns nothing
  • Node class
    • implements the INode interface
    • Draw call (virtual void with 1 argument of type matrix) simply calls each child INode's Draw method.
  • various classes that derive from Node
    • these are actual nodes and can be transformation nodes, leaf nodes, etc.
A: 

Its difficult to advise you as you have not given us too much information about your problem domain. Also you're mixing your terminology a little so I'm unclear if you see the leaf and transformation nodes as interfaces, abstract classes or classes.

I guess in terms of design you need to ask yourself what differentiates a leaf node from a transformation node. If it is just purely the properties of the node then perhaps using attributes may be the most elegant solution, but if they have different behaviours then it would point me towards separate classes.

Based on the names, we may be able to suppose the transformation node is "transformable" and so has a "Transform" method but a leaf not is not transformable. I'd suggest then that its better for the leaf node not to have a transform method and be in a different class.

Mark