I’ve a tree-like construction as proven in under image (as one small instance). The tree consists of two completely different node sorts, which might be:
- Information Nodes: These nodes which might be coloured in yellow comprise about ten attributes. They all the time seem within the leaves of the tree.
- Assortment Nodes: Which can be proven in blue. They’re sharing
Sortattributes with the
Information Nodesand likewise maintain an ordered record of their kids.
This tree is created in a single element and despatched to a different system for manipulation (Saving, displaying in GUI, and many others.). To design this tree, there are completely different approaches that I’ve described under with their benefits and drawbacks. What do you concentrate on them and which one is probably the most applicable one on this case?
Have a interface for widespread functionalities (e.g.
getType) and put the precise functionalities (e.g.
getChildren) in concrete courses. This manner, the opposite software that should manipulate the tree (for saving or displaying in GUI), wants plenty of down-casing based mostly on the kind of the node.
Have one interface for all the functionalities of each node sorts. In every concrete class, both implement the tactic (if relevant) or throw an exception. It’s the duty of the consumer to name the proper technique based mostly on the kind of the node.
Don’t go for an interface. However simply have one class (e.g.
TreeNode) with the all information + strategies of each node sorts. It’s once more the duty of the consumer to name the proper technique on the proper object kind.
p.s. The implementation language shall be C++11, if it issues.