Is this a good way to set this up?
My original code consisted of dozens of Dictionary(Of String, SortedDictionary(Of Date, Double))
But I am a fairly novice programmer and would love to know if there is a more efficient architecture for what I am trying to achieve.

The way I am currently setting this up is very hard to debug - For example, the Count property of my RestaurantData throws an exception of type System.TypeLoadException.

Overall, this solution is working perfectly well, but I would like to learn from this about how to become a better .Net & OOP programmer.

Why do you need a SortedDictionary? Other options are: just to sort incoming data by dates and store in array or list; use SortedList
–
almazDec 12 '12 at 14:38

@almaz, Thanks for the comment and answer. Just to understand how you would suggest doing this, you would simply use a dictionary and have a separate SortedList(Of Date) that I oculd use to hold the keys in a sorted fashion?
–
John BustosDec 12 '12 at 14:51

2

SortedList<TKey, TValue> is pretty much the same as SortedDictionary<TKey, TValue>, the difference is in internal data structures, memory consumption and performance of addition/searching
–
almazDec 12 '12 at 15:45

1 Answer
1

Inheriting from collections is rarely a good practice. In your case it's better to have a private collection (SortedDictionary in your case), and populate it as needed (in other words it's better to use delegation than inheritance here).

The reason why inheriting is not so good here is that your class will expose a lot of functionality that users of RestaurantData aren't actually interested in.

Thanks for the response - Just to understand (since this is all fairly new to me), you are suggesting my initial approach of just having a series of Dictionary(Of...) in my code rather than creating custom objects? My logic for going this way was that it allowed me to create extra Add events and constructors for these specific classes... As a larger-scale question, when do you decide to delegate rather than inherit? Thanks!!
–
John BustosDec 12 '12 at 14:50

1

@JohnBustos: No, you will have one private SortedDictionary inside your RestaurantData class and will potentially have public methods in that class similar to those in SortedDictionary. It is possible that you will want to implement IDictionary or IEnumerable (e.g., so that you can use Linq on RestaurantData).
–
BrianDec 12 '12 at 14:54

Aaaaaah, @Brian... Ok, that's beginning to make sense to me and my thick skull... So I would still have those 3 different classes, just not inherit the Dictionary / SortedDictionary. Another question - the way I have it programmed now allows me to write my code along the lines of MyRestaurantDict("RestName")(#Date#).Var1 - How could I get the same functionality / ease of referencing without inheriting the dictionary classes? Could you (or someone) just point me in the right direction as to how my class definitions could look? Thanks!!!
–
John BustosDec 12 '12 at 15:37

@JohnBustos You would have to create a new method GetDateData(Date) in RestaurantData that will return required DateData object
–
almazDec 12 '12 at 15:53