I am trying to make this example as natural as possible to make it simple. Lets say I have groups of items. eg item1, item2, item3, item4 etc
currently item is represented by struct
// only contains data
struct item{
string name;
std::vector<string> parts_name;
std::vector<double> parts_price;
std::vector<string> item_color;
...
};
itemx item1, item2...
Then I have class called items
class items{
public:
// return name of all items
vector<string> get_all_item();
// return price of all parts
vector<string> get_all_parts_price();
private:
// hold vector of item
vector<shared_ptr<item>> list_of_items;
// name of item and its parts price
// eg: <item_1_part_1, $1.3>
// eg: <item_1_part_2, $2.3>
// eg: <item_2_part_1, $4.3>
map<string, double> parts_prices;
};
The problem with my current items class is that it is growing really huge, as feature of item increases.
My solution :
make struct item contain function which distributes load to struct item from class items.
Is there any other better way or any design pattern that is meant for this kind of problem?
Aucun commentaire:
Enregistrer un commentaire