I have a class hierarchy as such:
+-- VirtualNode
|
INode --+ +-- SiteNode
| |
+-- AbstractNode --+
|
+-- SiteSubNode
And a corresponding NodeCollection
class that is build on INode
. In order to display a NodeCollection
I need to know the final type of each member. So I need a function like this
foreach (INode n in myNodeCollection)
{
switch(n.GetType())
{
case(typeof(SiteNode)):
// Display n as SiteNode
}
}
Now, this is really not an object oriented way of doing it. Are there any patterns or recommended ways of doing the same thing, in your opinion?
EDIT
I already thought of adding a Display
or Render
method to the INode interface. That has the side effect of coupling the view to the model, which I would really like to avoid.