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

 

posted @ 2012-09-11 09:36  dushuai  阅读(145)  评论(0编辑  收藏  举报