为什么在 VBA 中实现接口时参数重命名为 RHS?
Why are arguments renamed to RHS when implementing an Interface in VBA?
当您在 Class 中实现接口时,参数会自动命名为 RHS,如 MDSN https://msdn.microsoft.com/en-us/library/office/gg264387.aspx
所示
例如,如果我这样创建 IInterface:
Public Property Let Value1(strValue1 As String)
End Property
Public Property Let Value2(strValue2 As String)
End Property
并实现它,class 看起来像这样:
Implements IInterface
Private Property Let IInterface_Value1(RHS As String)
End Property
Private Property Let IInterface_Value2(RHS As String)
End Property
最好以提供某种程度的抽象并使代码更易于阅读和编写的方式命名参数。在我实现这些语句之后,我实际上可以将 class 中的参数更改为我想要的任何参数,如下所示,但我的问题是为什么会发生这种情况? RHS 是另一种语言的遗留物,还是有特殊原因将其命名为这样?
Implements IInterface
Private Property Let IInterface_Value1(strValue1 As String)
End Property
Private Property Let IInterface_Value2(strValue2 As String)
End Property
如果我手动更改上面的代码,编译会很好。
rhs
代表 运算符 = 的右侧,lhs
代表 = 的 左侧.这里为什么要这样命名呢?也许它来自 c++
约定。根据您考虑此代码的属性:
Dim test As IInterface
Set test = New ClassTest
test.Value1 = "rhsVal"
新字符串值实际上在 =
的右侧,因此 rhs
。
当您在 Class 中实现接口时,参数会自动命名为 RHS,如 MDSN https://msdn.microsoft.com/en-us/library/office/gg264387.aspx
所示例如,如果我这样创建 IInterface:
Public Property Let Value1(strValue1 As String)
End Property
Public Property Let Value2(strValue2 As String)
End Property
并实现它,class 看起来像这样:
Implements IInterface
Private Property Let IInterface_Value1(RHS As String)
End Property
Private Property Let IInterface_Value2(RHS As String)
End Property
最好以提供某种程度的抽象并使代码更易于阅读和编写的方式命名参数。在我实现这些语句之后,我实际上可以将 class 中的参数更改为我想要的任何参数,如下所示,但我的问题是为什么会发生这种情况? RHS 是另一种语言的遗留物,还是有特殊原因将其命名为这样?
Implements IInterface
Private Property Let IInterface_Value1(strValue1 As String)
End Property
Private Property Let IInterface_Value2(strValue2 As String)
End Property
如果我手动更改上面的代码,编译会很好。
rhs
代表 运算符 = 的右侧,lhs
代表 = 的 左侧.这里为什么要这样命名呢?也许它来自 c++
约定。根据您考虑此代码的属性:
Dim test As IInterface
Set test = New ClassTest
test.Value1 = "rhsVal"
新字符串值实际上在 =
的右侧,因此 rhs
。