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.
tshepang
  • 12,111
  • 21
  • 91
  • 136
RCIX
  • 38,647
  • 50
  • 150
  • 207
  • This might help a bit: http://blogs.msdn.com/ericlippert/archive/2009/02/02/properties-vs-attributes.aspx – Eric Lippert Jun 22 '09 at 01:53
  • That would seem to indicate that i shoud use attributes (i am trying to indicate what type of node that derived classes are), however i am not entirely convinced that this is the best option. – RCIX Jun 22 '09 at 02:10
  • Is the type of node a fact about the mechanism of the class, or a fact about what the class is being used to represent? – Eric Lippert Jun 22 '09 at 13:53
  • A fact about what the class is being used to represent. – RCIX Jun 22 '09 at 23:05
  • Then I would avoid using an attribute. Use attributes to describe a fact about *the class* itself, like "this class can serialize its state to disk", or "this class shouldn't show up in the debugger". Attributes tell you about the mechanism used to implement a concept, not about the concept itself. – Eric Lippert Jun 23 '09 at 05:07
  • All right, thanks. I unfortunately cannot accept comments as answers, so if you provide one i'll be happy to accept it. – RCIX Jun 23 '09 at 05:20

1 Answers1

0

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
  • 2,392
  • 4
  • 21
  • 42