jeudi 20 juillet 2017

What design pattern to use while designing district?

Lets say I am trying to design a district. I have

         1) house
         2) community (groups of 2 or more then 2 house)
         3) city (group of more then two community)
         4) district (groups of 2 or more then 2 city) 

What I have so far :

class house{
   public: 
    house(std::string name, std::string id);
    std::string get_name();
    std::string get_id();
  private:
   std::string name;
   std::string id;

};

class community{
   public:
      community();
      // get house names
     std::vector<std::string> get_all_house_in_community();
   private:
     std::string name;
     std::vector<house> p_houses; // vector of house 
};

class city{
   public:
      city();
      // get house names by collecting from communities
      std::vector<std::string> get_all_house_in_city();
   private:
     std::string name;
     std::vector<community> p_communities; // vector of community
}

class district{
   public:
     district();

     // get house names from city
     std::vector<std::string> get_all_house_in_district();
   private:
     std::string name;
      std::vector<city> p_cities; 

};

When the get_all_house_in_district() function is called it has to call all the get_all_housexxxx of the classes. Is it a good idea to distribute data among classes this way or should the district hold all the houses(If I let district hold all the houses then the district class gets really complicated really quickly)?

side question : should I use inheritance here, I don't see any reason but was just curious.

Is there any design pattern to represent this scenario?

Aucun commentaire:

Enregistrer un commentaire