jeudi 4 mai 2017

Parent element in child class

The real world example is quite simple. There is a house and the house has walls and so on.

class Room {
    public List<Wall> Walls{get; set;}
}

class Wall {
    public List<WallObject> WallObjects{get; set;}
}

Now a developer has added the property room to the class wall a few years ago:

class Wall {
public List<WallObject> WallObjects{get; set;}
public Room Room{ get; set; }
}

It is very pleasant to have this object in the class. One has access to the parent element in many places (430). But I think it does not belong there and sometimes leads to errors, because you do not set or change it.

Are there are other approaches, except for methods handover in many cases.

Aucun commentaire:

Enregistrer un commentaire