Lets say I have the following code:
public class Base
{
// Some stuff here
public int var
}
public class UsingBase
{
// Some more stuff here
public Base B = new Base();
}
Now let's say the actual code of these classes is huge and I would like UsingBase to do some extra stuff. So I'm thinking about subclassing it. Now let's say that what I really want to do is add a method that gives me two times var. Since var is a field of Base, it would be more elegant to add the method to a subclass of Base, and not to a subclass of UsingBase. But I don't want to rewrite UsingBase, and UsingBase uses Base and not my subclass of Base. Actually, this is exactly what I want to do:
TreeView (.NET) has a property of type TreeNodeCollection called Nodes that stores a bunch of objects of type TreeNode. Each TreeNode in Nodes can have a Tag that I can use to store any object I want. But the class TreeNodeCollection doesn't have a function that gives me the TreeNode that correspond to a certain Tag. So I want to be able to do this:
TreeView myTreeView = new TreeView();
// Add some TreeNode's and asign unique tags to each of them
TreeNode someNode = myTreeView.Nodes.GetNodeByTag(object Tag);
I know I can subclass TreeView and add a function that does that, but I just like the other solution a lot better. So I'm wondering if that's possible.