If I have two objects, Parentand Child, Parentshould know about all its children Child, and each instance Childshould know about its parent instance Parent, how do I do it right (from the point of view of DDD, etc.)?
An easy way would be to do it parent.addChild(new Child(parent)), but it seems ugly - and also:
parent.addChild(new Child()); // Then call some setParent method on child, which needs to be public
Do I need to use a factory here? And if so, how?
thank
source
share