Pytanie trywialne, proszę tylko o poradę jak najlepiej to zrobić.
Wyobraźmy sobie osiedle domków, które wiadomo składa się z domków, każdy domek z pięter, a każde piętro z pokoi. Chcielibyśmy tworzyć całe osiedla domków.
Tworzymy taki model klas:
Pokój:
class Room
{
public int Id { get; set; }
public int Height { get; set; }
public int Width { get; set; }
public string Name { get; set; }
public string DispalyName { get; set; }
public Room(int id, int height, int width,string name, string displayName)
{
this.Id = id;
this.Height = height;
this.Width = width;
this.Name = name;
this.DispalyName = displayName;
}
Piętro:
class Floor
{
public int Id { get; set; }
public int FloorNumber { get; set; }
public string Name { get; set; }
public string DispalyName { get; set; }
public IEnumerable<Room> RoomsCollection { get; set; }
public Floor(int id, int floorNumber,string name, string displayName, IEnumerable<Room> roomsColection=null)
{
this.Id = id;
this.FloorNumber = floorNumber;
this.Name = name;
this.DispalyName = displayName;
this.RoomsCollection = roomsColection;
}
}
Dom:
class House
{
public int Id { get; set; }
public string Name { get; set; }
public string DisplayName { get; set; }
public IEnumerable<Floor> FloorsCollection { get; set; }
public House(int id, string name, string displayName, IEnumerable<Floor> floorsCollection=null)
{
this.Id = id;
this.Name = name;
this.DisplayName = displayName;
this.FloorsCollection = floorsCollection;
}
}
Osiedle:
class HousingEstate
{
public double Height { get; set; }
public double Width { get; set; }
public IEnumerable<House> HousesCollection { get; set; }
public HousingEstate(double height, double width, IEnumerable<House> housesCollection=null)
{
this.Height = height;
this.Width = width;
this.HousesCollection = housesCollection;
}
}
Pytanie jest takie czy tworzenie kolekcji w konstruktorze jest poprawne, czy lepiej inaczej to zrobić, jeśli chcemy tworzyć wszystko chaotycznie. W sytuacji gdy użytkownik ma okienko do tworzenia całego osiedla, w tym domków, pięter i pokoi i robi to niepoprawnie(w sensie nie od dołu hierarchii tak jakby) czyli np.:
Tworzy osiedle, potem 2 pokoje, potem domek, potem 3 pietra, potem pokoje do pięter i zaczyna następny domek itd...