Design Advice - Dictionaries

I’m unsure which collection type to use in my Request DTO. Dictionaries are the easiest to work in this case as the Key ensures the uniqueness at schema level. However long term I’m not sure if I’ll run into trouble.

To experienced services designers, which would be the preferred approach out of these choices?

A

public class UpdateAdditionalInformation
{
    public string Code { get; set; }
    public Dictionary<int, string> AdditionalInformation { get; set; } // dictionary of AdditionalFieldId and Value
}

B

public class UpdateAdditionalInformation
{
    public string Code { get; set; }
    public List<AdditionalInformationItem> AdditionalInformation { get; set; }
}

public class AdditionalInformationItem
{
    public int AdditionalFieldId { get; set; } // id of field metadata
    public string Value { get; set; }
}

C

public class UpdateAdditionalInformation
{
    public string Code { get; set; }
    public Dictionary<int, AdditionalInformationItem> AdditionalInformation { get; set; }
}

public class AdditionalInformationItem
{
    public string Value { get; set; }
    // Possibly expanded in the future
}

In my opinion case B is more suitable, because if you need to extend AdditionalInformationItem in future you can easily add new properties to it (case A does not allow to do it) and also it contains Id field which can be filled when query this type from database in single instruction without additional coding for saving Id (which is required in case C). This can be usable if you need to write GetAdditionalInformation method in future.

2 Likes

Thanks for sharing your opinion @xplicit. Much appreciated.