vb6的多态,继承,小见解,
vb6的多态,可以用,类模块的方式简单实现,
个人觉得它没有接口这概念,
可以理解为不写具体实现的抽象类,
,
举例,
被继承类(或接口或抽象类):iClass1
两个继承:CA,CB
成员属性,与成员方法的继承覆盖略有不同,成员属性,需要用let,get访问器
代码:
iClass1.vb(类模块)
--------------------------
public item1 as boolean
public function item2(byval a as long) as string
msgbox "iClass1-item2"
end function
--------------------------
CA.vb(类模块)
--------------------------
Implements iClass
private aitem1 as boolean '定义一个私有
public property let iClass1_item1(byval val as boolean)
aitem1=val
end property
public property get iClass1_item1() as boolean
iClass1_item1=aitem1
end property
public function iClass1_item2(byval a as long) as string
msgbox "CA-item2"
end function
--------------------------
CB.vb(类模块,实现和CA.vb类似,这里就不写了,只改,在其iClass1_item2方法中输出为 CB-item2 字符串)
--------------------------
--------------------------
调用与测试:
private a1 as iClass1 '这里定义一个iClass1,下面用到它的多态方法
sub init()
set a1=new CA()
call a1.item2
set a1=new CB()
call a1.item2
end sub
--------------------------
继承 ,
没找到好方法....