QTP设计模式-命令包装模式
'命令包装模式举例:
'定义一个oCommand类
Class oCommand
'定义输入
Private VarIntNum
Public Property Get Number
Number = VarIntNum
End Property
Public Property Let Number(ByVal oNum)
VarIntNum = oNum
End Property
'定义输出
Private VarResult
Public Property Get Result
Result = VarResult
End Property
Public Property Let Result(ByVal oResult)
VarResult = oResult
End Property
'默认主函数
Public Default Function Exec()
Me.Result = Number * Number
Exec = Me.Result
End Function
End Class
'构造一个构造器
Function Constructor(ByVal newNumber)
Set Constructor = New oCommand
Constructor.Number = newNumber
End Function
'调用构造器并输入参数
Set con1 = Constructor(3)
'命令模式
Call con1
'获取命令执行结果
MsgBox con1.result