zoukankan      html  css  js  c++  java
  • 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也许就是一个好的选择了,至少使用起来要好一点。

  • 相关阅读:
    Android编译系统分析四:实战-新增一个产品
    Android编译系统分析三:make完整编译android系统
    Android编译系统分析二:mm编译单个模块
    【python】-文件操作1
    【python】-文件操作
    【python】-集合操作
    【python】-字典的使用
    【python】-字符串常用操作
    【python】-编程练习
    解释型语言与编译型语言
  • 原文地址:https://www.cnblogs.com/Duiker/p/261528.html
Copyright © 2011-2022 走看看