As an example, suppose I had a large amount of data about a set of Restaurants for a large set of Dates in a database that I need to analyze / output to the user.
So, in my code, I have a custom class that holds the data for each restaurant for each date - For example:
Public Class DateData
Public Property Var1 As Double = 0
Public Property Var2 As Double = 0
Public Property Var3 As Double = 0
Public Property Var4 As Double = 0
Public Sub Sub1()
....
End Sub
... etc ....
End Class
And since I am getting this data for each date (and since date-order does matter for my calculations), I have the following class set up too (where most of the work / calculation is done):
Public Class RestaurantData
Inherits SortedDictionary(Of Date, DateData)
Public Property Name As String
Public Property RestaurantLevelData1 As Double = 0
Public Property RestaurantLevelData2 As Double = 0
Public Sub New(ByVal strName As String, ByVal DatesList As List(Of Date))
_Name = strName
For Each daDate As Date In DatesList
Me.Add(daDate)
Next
End Sub
Public Overloads Sub Add(ByVal daDate As Date)
MyBase.Add(daDate, New DateData)
End Sub
Public Sub Sub1()
For i As Integer = 0 To Me.Keys.Count - 1
Dim daDate As Date = Me.Keys(i)
Me(daDate).Sub1()
.... etc ....
Next
End Sub
... etc ....
End Class
And, finally, since this is for a large amount of restaurants, I have a class which holds this Dictionary on a restaurant level - For example:
Public Class RestaurantsDict
Inherits Dictionary(Of String, RestaurantData)
Public Overloads Sub Add(ByVal strName As String, ByVal Dates As List(Of Date))
MyBase.Add(strName, New RestaurantData(strName, Dates))
End Sub
End Class
Ok, so now that I've set this up, I have 2 main questions:
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
Countproperty of myRestaurantDatathrows an exception of typeSystem.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.
SortedDictionary? Other options are: just to sort incoming data by dates and store in array or list; useSortedList– almaz Dec 12 '12 at 14:38SortedList<TKey, TValue>is pretty much the same asSortedDictionary<TKey, TValue>, the difference is in internal data structures, memory consumption and performance of addition/searching – almaz Dec 12 '12 at 15:45