Вопрос

I have a class ObjectBatch as follows:

[Serializable]    
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?
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top