51Testing软件测试论坛
标题:
又出错错错啦!!赵旭斌老师书中类的继承模式例子
[打印本页]
作者:
yinjiajia0626
时间:
2014-8-5 16:44
标题:
又出错错错啦!!赵旭斌老师书中类的继承模式例子
本帖最后由 yinjiajia0626 于 2014-8-6 13:55 编辑
求大神看!出错图片[attach]91357[/attach]
不知道是不是书印刷错误,if和else里面的内容一样啊,都是 child(key)=super(key)
源代码如下:
Class ClassHelper
Private dict
'添加方法
Public default function addMethod(name)
Set dict(name)=getRef(dict("type")&name)
End Function
'创建字典对象
Private function CreateDict()
Set CreateDict=CreateObject("scripting.dictionary")
End Function
'复制字典对象
Private function CopyDict(super,child)
Dim key
For each key in super
If isobject(super(key)) Then
Set child(key)=super(key)
Else
child(key)=super(key)
End If
Next
Set CopyDict=child
End Function
'新建一个类
Public function newClass(name)
Set dict=CreateDict()
dict("type")=name
Set newClass=dict
End Function
'继承方法
Public function extends(super,childType)
Set dict=CopyDict(super,child)
Set dict("parent")=super
dict("type")=childType
Set extends=dict
End Function
'新建继承类
Public function [new](super,arrParams)
Dim dict:set dict=CopyDict(super,CreateDict())
Call dict("initialize")(dict,arrParams)
Set [new]=dict
End Function
End Class
'载入继承帮助类
Dim Mercury:set Mercury=new ClassHelper
'###################################################
'创建一个AutoTestTools新类
Dim AutoTestTools:Set AutoTestTools=Mercury.newClass("AutoTestTools")
AutoTestTools("effect")="Automation Testing"
Function AutoTestToolsInitialize(this,arrParams)
this("effect")=arrParams(0)
End Function : Mercury "initialize"
Function AutoTestToolsLaunch()
MsgBox "Launch AutoTestTools"
End Function : Mercury "Launch"
''End Class
'####################################################
'####################################################
'创建一个新继承AutoTestTools的类
Dim QuickTest : set QuickTest=Mercury.extends(AutoTestTools,"QuickTest")
Quicktest("name")="Quick Test Professional"
QuickTest("support")="all"
Function QuickTestInitialize(this,arrParams)
this("support")=arrParams(0)
End Function : QuickTest "initialize"
Function QuickTestLaunch()
MsgBox "Launch QuickTest"
End Function : Mercury "Launch"
''End Class
'####################################################
'初始化QuickTest类
Dim QuickTestCls: set QuickTestCls=Mercury.new(QuickTest,array("web"))
'打印support数学,此时已经被初始化为web
MsgBox QuickTestCls("support")
'执行QuickTest类中的Launch方法
Call QuickTestCls("Launch")()
'执行QuickTest类的父类的Launch方法
Call QuickTestCls("parent")("Launch")
复制代码
作者:
赵佳乐SMILE
时间:
2014-8-6 14:12
高大上
作者:
yinjiajia0626
时间:
2014-8-9 08:46
不要沉啊,问题还没有解决呢
作者:
Shawn_xiao
时间:
2014-8-12 12:51
这本书刊误确实不少:1.CopyDict中需要加Set child = CreateObject("scripting.dictionary")
2.function QuickTestInitialize 后面的QuickTest "initialize"应该改成Mercury "Initialize" 才能那个将前面的方法加进字典
作者:
yinjiajia0626
时间:
2014-8-14 10:02
回复
4#
Shawn_xiao
太谢谢你啦!!
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2