I bump into this from time to time during class design... when I have several properties of the same type in the object. Take few examples:
User has several addresses. We can do
IDictionary<string, Address> Addresses; // Addresses["BusinessAddress"];
or
Address BusinessAddress;
Address ShippingAddress;
Product has related products, by different cagetories. We can do
IDictionary<string, IList<Product>> Related; // Related["Available"];
or
IList<Product> Available;
IList<Product> Required;
User has several roles assigned. We can do
IList<Role> Roles;
or
bool IsAdmin;
bool IsSales;
So, what's better? IDictionary is more flexible as we can easily add new address categories into the database without even touching the code. But the drawback is that we use strings to access; this is always error-prone. We can solve this with either unit tests or constants like
public class ProductCategories { public static string Available = "Available"; }
But it is still much worse to read "product.Available" than "product.Related[ProductCategories.Available]".
There are other considerations, like, what's easier/better to map with ORM (e.g. NHibernate).
But the question is, are there any known preferences? Design articles and/or books on this subject? Real world practices that people here experienced?
For example, we can combine both worlds... have IList and bool IsAdmin doing "return Roles.Contain(Role("Admin"));". But this looks ugly to me.
Or, in case of IDictionary we can't have more than 1 address per type; and if we do
IDictionary<string, IList<Address>>
this is going crazy for simple addresses where we don't need multiples. But if we use BillingAddress, ShippingAddress, and IList for MultipleAddress, we have a much more fine-grained control over our addresses... with Intellisense and so on.