Hi Guys,
I have a tree structure design problem, and i can't think of a way out.
i want to have one class Tree containing a generic data, and extend the Tree class with ComplexTree that will contain more methods like Iterate, DoSomthingOnComplex, etc.
here is a sample of the code i have:
class Tree<TData>
{
public TData Data { get; set; }
public ICollection<Tree<TData>> Children { get; private set; }
public Tree<Data>(TData data)
{
// ...
}
public void Iterate(Action<TData> action)
{
action(Data);
Children.ForEach(x => x.Iterate(action));
}
}
class ComplexTree<TData> : Tree<TData>
{
public int ComplexValue1 { get; set; }
public int ComplexValue2 { get; set; }
public ComplexTree(TData data, int cv1, int cv2)
: base(data)
{
// ...
}
public void DoComplexStuffOnTree()
{
// ... might want to use the base methods here
}
}
problem is that for one thing, i can't really expose the collection that holds Tree to anyone that has create ComplexTree and i can't use Iterate for the ComplexTree because i can't use the cv1, cv2 values that belong only to the inheriting tree.
is there an obvious solution i'm missing? should i not use inheritance? should rewrite all the methods?
Thanks, John