I have the following hierarchy of classes in a problem that I am working on.
DiscountEvent
DiscountGroup
ProductFamily
Product
where each class contains a collection of next one (e.g. DiscountEvent contains a collection of DiscountGroups, etc)
This kind of a somewhat deep hierarchy results in many chained calls from the higher modules.
For example, while reading product data from the database into this class hierarchy I have chains of calls and similar AddProduct
methods.
class DiscountEvent{
Dictionary<int, DiscountGroup> DiscountGroups;
public void AddProduct(ProductInfo info){
DiscountGroups[info.groupId].AddProduct(info);
}
...
}
class DiscountGroup{
Dictionary<int, productFamily> productFamilies;
public void AddProduct(ProductInfo info){
productFamilies[info.familyId].AddProduct(info);
}
...
}
...
Similar add methods all the way to the leaf class. Can you think of any way to simplify this kind of a hierarchical class structure?