我有一个非常人为的例子来说明我的业务对象如何加载它们的数据。但是,我想防止下面展示的情况。我知道这里有缺点,但它就是这样(到目前为止)!如何在不重组接口等的情况下实现这一目标?
Public Class Car
Public Property Passengers As Integer
Public Shared Sub Fill(c As Car, r As SqlDataReader)
Passengers = r.GetInt32(0)
End Sub
End Class
Public Class UsedCar
Inherits Car
Public Property PreviousOwner As String
Public Shared Sub FillUsed(l As Limo, r As SqlDataReader)
Passengers = r.GetInt32(0)
PreviousOwner = r.GetString(1)
End Sub
End Class
Public Sub CreateVehicles()
Dim c As New Car()
Car.FillWithStuff(c, GetSqlReader(carId))
Dim l As New UsedCar()
UsedCar.FillUsed(l, GetSqlReader(usedCarId)) 'Great
Car.Fill(l, GetSqlReader(usedCarId)) 'No! << Stop this at once!
UsedCar.Fill(l, GetSqlReader(usedCarId)) '<<< Even more wrong!
End Sub