VB6-没办法的对象Wrapper

博客指出TestCommand继承Command接口后,采用不同声明方式分别无法访问Count属性和Execute方法,直接在TestCommand中实现Public的Execute或声明多个对象赋值的方式都不理想,提出使用CommandWrapper来解决该问题,使用体验更好。

请先看下边得代码:

None.gif'Interface Command
None.gif
Public Sub Execute(): End Sub
None.gif
None.gif
'TestCommand
None.gif
Implements VB6DPFrameWork.Command
None.gif
None.gif
Public Count As Integer
None.gif
None.gif
Private Sub Command_Execute()
None.gif    Count 
= 1
None.gif
End Sub
None.gif
None.gif
'CommandWrapper
None.gif
Private mSelf As TestCommand
None.gif
None.gif
Private mInterface As VB6DPFrameWork.Command
None.gif
None.gif
Public Sub Dispose()
None.gif    
Set mSelf = Nothing
None.gif    
Set mInterface = Nothing
None.gif
End Sub
None.gif
None.gif
Public Sub Instance()
None.gif    
If mInterface Is Nothing Then
None.gif        
Set mInterface = New TestCommand
None.gif        
Set mSelf = mInterface
None.gif    
End If
None.gif
End Sub
None.gif
None.gif
Public Function Interface() As VB6DPFrameWork.Command
None.gif    Instance
None.gif    
Set Interface = mInterface
None.gif
End Function
None.gif
None.gif
Public Function Self() As TestCommand
None.gif    Instance
None.gif    
Set Self = mSelf
None.gif
End Function
None.gif
None.gif
'TestCase
None.gif
Public Sub Test_Wrapper(oTestResult As TestResult)
None.gif    
With oTestResult
None.gif        
Dim w As New CommandWrapper
None.gif        w.Interface.Execute
None.gif        .AssertEqualsLong w.Self.Count, 
1
None.gif        
Set w = Nothing
None.gif    
End With
None.gif
End Sub

TestCommand继承了Command接口,如果采用
dim t as command的方式,将不能访问Count属性。
如果采用
dim t as testcommand方式,将不能访问Execute方法。

这样用起来就很难受,当然,如果在TestCommand中实现一个Public的Execute当然可以,但是就不好了,也可以声明多个对象,然后进行赋值,这样也不好,为了解决这个问题,使用CommandWrapper也许就是一个好的选择了,至少使用起来要好一点。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值