例如,假设我有大量关于数据库中大量日期的一组餐厅的数据,我需要分析/输出给用户。
因此,在我的代码中,我有一个自定义类,其中包含每个日期的每个餐厅的数据 - 例如:
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
而且由于我得到了每个日期的这些数据(并且由于日期顺序对我的计算很重要),我也设置了以下类(大部分工作/计算完成的地方):
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
最后,由于这是针对大量餐厅的,所以我有一个类在餐厅级别上保存此字典 - 例如:
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
好的,既然我已经设置好了,我有两个主要问题:
这是设置它的好方法吗?我的原始代码由几十个组成,
Dictionary(Of String, SortedDictionary(Of Date, Double))
但我是一个相当新手的程序员,很想知道是否有更有效的架构来实现我想要实现的目标。我目前设置它的方式很难调试 - 例如,
Count
我的属性RestaurantData
抛出 type 的异常System.TypeLoadException
。
总的来说,这个解决方案运行良好,但我想从中学习如何成为一个更好的 .Net 和 OOP 程序员。
谢谢!