• VB6没办法的对象Wrapper


    请先看下边得代码:

    '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 Sub

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

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

  • 相关阅读:
    POJ 3280 Cheapest Palindrome (区间DP)
    UVaLive 4731 Cellular Network (期望DP)
    UVa 11404 Palindromic Subsequence (LCS)
    UVa 11552 Fewest Flops (DP)
    UVa 10534 Wavio Sequence (LIS+暴力)
    UVaLive 4256 Salesmen (简单DP)
    UVaLive 4094 WonderTeam (贪心)
    UVaLive 3266 Tian Ji -- The Horse Racing (贪心)
    POJ 3723 Conscription (最小生成树)
    NodeJS学习笔记 进阶 (4)基于express+muter的文件上传(ok)
  • 原文地址:https://www.cnblogs.com/Duiker/p/261528.html
Copyright © 2020-2023  润新知