请先看下边得代码:
'Interface Command
Public Sub Execute(): End Sub
'TestCommand
Implements VB6DPFrameWork.Command
Public Count As Integer
Private Sub Command_Execute()
Count = 1
End Sub
'CommandWrapper
Private mSelf As TestCommand
Private mInterface As VB6DPFrameWork.Command
Public Sub Dispose()
Set mSelf = Nothing
Set mInterface = Nothing
End Sub
Public Sub Instance()
If mInterface Is Nothing Then
Set mInterface = New TestCommand
Set mSelf = mInterface
End If
End Sub
Public Function Interface() As VB6DPFrameWork.Command
Instance
Set Interface = mInterface
End Function
Public Function Self() As TestCommand
Instance
Set Self = mSelf
End Function
'TestCase
Public Sub Test_Wrapper(oTestResult As TestResult)
With oTestResult
Dim w As New CommandWrapper
w.Interface.Execute
.AssertEqualsLong w.Self.Count, 1
Set w = Nothing
End With
End SubTestCommand继承了Command接口,如果采用
dim t as command的方式,将不能访问Count属性。
如果采用
dim t as testcommand方式,将不能访问Execute方法。
这样用起来就很难受,当然,如果在TestCommand中实现一个Public的Execute当然可以,但是就不好了,也可以声明多个对象,然后进行赋值,这样也不好,为了解决这个问题,使用CommandWrapper也许就是一个好的选择了,至少使用起来要好一点。
博客指出TestCommand继承Command接口后,采用不同声明方式分别无法访问Count属性和Execute方法,直接在TestCommand中实现Public的Execute或声明多个对象赋值的方式都不理想,提出使用CommandWrapper来解决该问题,使用体验更好。
1637

被折叠的 条评论
为什么被折叠?



