玩VB已經(jīng)有1個星期左右了.覺得VB也是可以用OO的方式來開發(fā)應(yīng)用程序的.因為VB支持Com并且提供類模塊實現(xiàn)了封裝.同時也提供了接口的支持.通過Implements就可以實現(xiàn)接口.因此也就實現(xiàn)了繼承.如果
通過組合就可以達到繼承的效果.當然者應(yīng)該算做Adapter模式了.當然可以通過VB實現(xiàn)大多數(shù)面向?qū)ο蟮脑O(shè)計模式.并且也可以通過UML進行建模.因為VB支持引用傳遞消息.同時大多數(shù)OO特性也可以模擬實現(xiàn).
這里我介紹一種抽象類的實現(xiàn)其實只是一個引例.方法很簡單.就是通過接口定制契約.通過Com不可創(chuàng)建對象實現(xiàn)抽象類的不可創(chuàng)建性.通過Adapter模式模擬繼承實現(xiàn).
例子如下:
’接口部分
Public Function AbstructFun() As String
End Function
’不可創(chuàng)建對象(用來實現(xiàn)抽象方法)把Instancing設(shè)置為 publicNoCreatable
Implements ImyInterFace
Public Function ImyInterFace_AbstructFun() As String
ImyInterFace_AbstructFun = "我起床"
End Function
’實現(xiàn)部分
Implements ImyInterFace
Public Function ImyInterFace_AbstructFun() As String
Dim ac As New AbstructClass
ImyInterFace_AbstructFun = ac.ImyInterFace_AbstructFun & "我吃早飯"
End Function