I have recently come across this issue. I, and others I talked with, came up with two choices:
- Do what you are doing with the
Parent<-->Child
relationship, both knowing about each other. - Have a
Parent-->Child
relationship and make everything be handled at the parent.
Both are viable solutions, but both have their issues. The first case, what you are doing, seems better and Microsoft seems to use this with their TreeView/TreeNode
and DataTable/DataRow/etc.
objects for example, because they can each reference back to their respective parents.
Maybe add constraints to the parent, such as not allowing access to the parent's child-collection directly, but only allowing an AddChild
function in which you can do the necessary linking. Or do what @Irfan suggests and have the child require you pass the parent to its constructor. Constrain your copy method as well, but always document everything to remove as much confusion as possible.
The later of the above examples is a little easier as everything is always accessed from the parent. This was our solution. We have many functions in the parent to check for and manage the children within. So in this case you would select the child in the CAD app then go to the parents and check in their collection to see if the child exists there. If it does you select the parent and the rest of the children.
It's up to you, but in each case you need to add constraints and error checking to make sure things happen as close to your desired way as possible. Hope this helps.