VB实现抽象类 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    VB是可以用OO的方式来开发应用程序的,

VB实现抽象类

。因为VB支持Com并且提供类模块实现了封装。同时也提供了接口的支持。通过Implements就可以实现接口。因此也就实现了继承。如果通过组合就可以达到继承的效果。当然者应该算做Adapter模式了。当然可以通过VB实现大多数面向对象的设计模式。并且也可以通过UML进行建模。因为VB支持引用传递消息。同时大多数OO特性也可以模拟实现。www.dnzg.cn

    这里我介绍一种抽象类的实现其实只是一个引例。方法很简单。就是通过接口定制契约。通过Com不可创建对象实现抽象类的不可创建性。通过Adapter模式模拟继承实现。

    例子如下:

    '接口部分

    Public Function AbstructFun() As String

    End Function

    '不可创建对象(用来实现抽象方法)把Instancing设置为 publicNoCreatable

    Implements ImyInterFace

    Public Function ImyInterFace_AbstructFun() As String

    ImyInterFace_AbstructFun = "我起床"

    End Function

    '实现部分

    Implements ImyInterFace

    Public Function ImyInterFace_AbstructFun() As String

    Dim ac As New AbstructClass

    ImyInterFace_AbstructFun = ac.ImyInterFace_AbstructFun & "我吃早饭"

    End Function

最新文章