M
Mike
I want to provide an abstract class to derive all nodes from. In the example
below Parent in the base class is of Type Node, but in the custom class I
want Parent to return a Type CustomNode. When CustomNode is accessed by a
helper class as Node Parent is always null. Is this a poor design, Im sure
it's a common problem and I am just missing something.
Note: I use virtual for Parent because abstract will not compile.
public abstract class Node
{
public virtual Node Parent
{
get { return null; }
}
public virtual bool IsLastChild
{
get { return this._isLastChild; }
}
private bool _isLastChild = false;
}
public class CustomNode : Node
{
public new CustomNode Parent
{
get { return this._customNode; }
}
private CustomNode _customNode = null;
}
below Parent in the base class is of Type Node, but in the custom class I
want Parent to return a Type CustomNode. When CustomNode is accessed by a
helper class as Node Parent is always null. Is this a poor design, Im sure
it's a common problem and I am just missing something.
Note: I use virtual for Parent because abstract will not compile.
public abstract class Node
{
public virtual Node Parent
{
get { return null; }
}
public virtual bool IsLastChild
{
get { return this._isLastChild; }
}
private bool _isLastChild = false;
}
public class CustomNode : Node
{
public new CustomNode Parent
{
get { return this._customNode; }
}
private CustomNode _customNode = null;
}