0
可以說我有這些類是否可以確定通過哪個對象訪問對象?
Public Class Connection
Private a as Node
Private b as Node
Public Property Self as Node
Public Property Other as Node
Public Sub New(a as Node, b as Node)
Me.a = a : Me.b = b
a.Connection = Me : b.Connection = Me
End Sub
End Class
Public Class Node
Public Connection as Connection
End Class
,我把它像這樣
Dim a = New Node()
Dim b = New Node()
Dim c = New Connection(a, b);
所以這兩個節點共享同一個連接對象。現在我試圖找出是否可以爲Connection屬性Self和Other定義一個getter,它可以檢測它們正在訪問哪個對象並相應地更改它們的返回值?
例如一些僞代碼
Public Property Other as Node
Get
If (<CalledThroughObject> = a) Then Return b
Return a
End Get
,這應該是勝負
a.Connection.Other = b
b.Connection.Other = a