When working with a single object there are a number of ways to segregate interfaces to it.
- Breaking it into smaller components that can be treated independently.
- Breaking it into simpler interfaces.
Both of these seem challenging to do with a tree. I think it would be nice to be able to do the following.
class Node : INodeData, INodePresentation { ... }
class Program
{
static void Main()
{
var node = new Node();
ManipulateNode(node);
PresentNode(node);
}
void ManipulateNode(INodeData nodeData)
{
foreach (INodeData child in nodeData.GetChildren())
nodeData.AddVertices(...);
nodeData.Rotate(...);
}
void PresentNode(INodePresentation nodePresentation)
{
nodePresentation.Color = Color.Blue;
nodePresentation.Size = 15;
nodePresentation.Paint();
foreach (INodePresentation child in nodePresentation.GetChildren())
PresentNode(child);
}
}
In this way different parts of the program could use the node according to a concise interface. But each interface I add will require more methods in the Node class which could be unmaintainable. It seems like the presentation and data should be defined in separate classes, but I can't think of a good way to do this while maintaining the ability to traverse the tree. Any suggestions?