Wrapping multiple Lists in IDictionary
I have a class ObjectBatch as follows:
[S开发者_JAVA百科erializable]
class ObjectBatch : IDictionary<string, IObjModel>
{
List<Tuple<string, IObjModel>> ModelATypes;
List<Tuple<string, IObjModel>> ModelBTypes;
List<Tuple<string, IObjModel>> ModelCTypes;
/* IDictionary implementations follow */
}
This class is solely responsible for adding/removing, modifying lists based on a property of IObjModel. Is this a bad design? It feels fine to me; however, since I haven't seen an implementation like this before, I was just wondering if this is bad, and if so, why?
Edit
Assume a unique string is enforced (but at a higher level) and that IObjModels are of a composite nature (composed at a higher level). Also, note the addition of the Serializable attribute - I forgot this initially.This class basically saves the elements of the individual collections. This class is not accessible by a user. It is an internal storage object.
This is fine as object composition, but you should not inherit this from Dictionary. What is the purpose of it? If you want user to search on this object using key, it will be return from which of 3 lists? If key or object is self descriptive to type of record, why storing them in different list?
ObjectBatch[key] <-- get from A or B or C?
Add(IobjectModel) <-- will add to which list?
精彩评论