考虑有许多产品的生产计划应用程序。每个产品都有一个在InventoryControlType上键入的InventoryControl对象列表。根据我们为生产计划运行的算法,我们需要访问给定产品的不同类型的InventoryControl对象。这工作正常。然而,今天我需要在InventoryControl中引入一个包含InventoryControlType的字段,因为我们深入了解我们需要了解InventoryControlType的算法。在此生产计划示例中,使用字典<enum,object>正确吗?
但是,我感觉我觉得我做错了什么,因为它看起来像我重复数据。
这个设计对你来说好吗?任何改进想法?
class Product{
Dictionary<InventoryControlType, InventoryControl> InventoryControls;
GetInventoryControl(InventoryControlType type){
return InventoryControls[type];
}
}
class InventoryControl{
InventoryControlType controlType;
float limit;
float cost;
...
CalculateCost(){...}
GetConstraint(){...}
}