I have made a base class Node with methods for adding and removing children, handling parents and searching for ancestors, descendants etc. So far so good.
Now I want to make a derived type TreeNode : Node that benifits from all these Node-features but at the same time restricting children and parent to have the same TreeNode type. As it is now I still have Node as type for children and parent.
Can I somehow make the property and method argument types of the Node class change to match the type of the derived class without having to manually override or "new"?
class Node
{
public TypeOfThisInstance Parent { get; }
}
class TreeNode : Node
{
}
TreeNode.Parent should now be a TreeNode and not a Node.
TreeNodedifferent fromNode?