通过将类传递给另一个类的构造函数来填充类类型的属性值,这有什么问题
请参见示例代码,其中GetData的构造方法将一个Data对象ByRef并填充它。在类GetData中具有单独的方法Function来填充并返回数据对象及其值,还是将其传递给构造函数,如示例代码所示,是更有意义还是更可取?
Public Class Data
Public Property Value1 As String
Public Property Value2 As String
End Class
'
Public Class GetData
Public Sub New(ByRef data As Data)
data.Value1 = "a"
data.Value2 = "b"
End Sub
End Class
'
Private Sub PopulateData()
Dim data As New Data
Dim gd As New GetData(data)
End Sub