Inheritance newbie...
I am an inheritance newbie.
Right now I have a method that accepts a “Node” parameter, which represents the root node of a tree structure.
The Node class has been inherited by several other classes, AndNode, OrNode, OperatorNode, TermNode, and so on.
The following doesn't work. I'm now looking for the “right“ way of doing this:
public string Process(Node node)
{
string buf;
switch (node.GetType())
{
case AndNode:
AndNode andNode = (AndNode)node;
buf = String.Concat(Process(andNode.left), “ and “, Process(andNode.right));
break;
case OrNode:
OrNode orNode = (orNode)node;
buf = String.Concat(Process(orNode.left), “ or “, Process(orNode.right));
break;
case TermNode:
TermNode termNode = (TermNode)node;
buf = termNode.term;
break;
.....
}
return buf;
}
Mike