我有2个类cls1, cls2分别有几个方法,若干属性
cls1
  implement ICls
  属性 code,name,address,cent,netn
  方法 save,new,check,dele
cls2
  implement ICls
  属性 code,name,ordern
  方法 save,new,dele然后建立一个接口类 ICls
  我只想把cls1, cls2公有类save,new,dele,code,name,写入接口ICls,
  其余的check,ordern分别写入cls1,cls2自身中,用public参数。
然后用以下语句调用
Private oBaseData As ICls
Private oShop As New cls1
Set oBaseData = oShop
发现,oBaseData 不能调用写在cls1类里面的public属性。我只有把2个类所有属性方法全部列在接口类 ICls里面,
又发现在cls1,cls2类中,必须写所有列在接口类 ICls里的属性方法实现过程,
好麻烦,谁能告诉我这种情况,应该使用怎样的模式,在VB6中实现呢谢谢,在线等待

解决方案 »

  1.   

    如果要使用Interface需要使用关键字implement.如下面的例子,child类继承超类同时使用接口IDraggable. class Child extends Parent implements IDraggable { 
    public function Child() { 
    // add Child constructor code 
    } public function startDrag():Void { 
    // implement the code for startDrag(); 
    } public function stopDrag():Void { 
    // implement the code for stopDrag(); 
    } public function isDragging():Boolean { 
    // implement the code for isDragging(); 

    } 唯一在使用接口时注意的事情是,在类中应使用与接口中一样的方法,参数类型的定义,通过这种方式接口可以在两个不一样的程序员之间标准化代码,当一个已知的接口被类使用时,和序员只需知道接口以在不同的类中使用.