- Oct 28, 2017
Just say myBuilding.AddFloor(newFloor). Then in the implementation of AddFloor say floors.Append(new Floor(this))I have a question related to design patterns (I'm using C#).
Let's assume that I have the following structure:
Building HAS (one or more) Floor HAS (one or more) Window
Currently each Building contains a list of Floor and each Floor contains a reference to its Building parent. The same logic applies to Window and Floor and their relationship.
I find it cumbersome having to reference the creator in each class constructor (e.g., myBuilding.AddFloor(myBuilding, newFloor))... but I need the children to be explicitly linked to their parent (in both directions... top-down and bottom-up).
Is there a better way of dealing with such a scenario?