日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
VB.NET接口實(shí)現(xiàn)多態(tài)實(shí)際代碼編寫

VB.NET編程語言為我們帶來了非常大的好處。而且其作為一項(xiàng)面向?qū)ο笳Z言,也有很多新的功能供大家使用。比如在多態(tài)性的實(shí)現(xiàn)方面就有很多方法。今天我們先來一起學(xué)習(xí)其中VB.NET接口實(shí)現(xiàn)多態(tài)的具體操作步驟。#t#

成都創(chuàng)新互聯(lián)主要從事網(wǎng)站設(shè)計制作、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)鹿邑,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108

VB.NET接口實(shí)現(xiàn)多態(tài)的實(shí)現(xiàn),能夠通過使用多接口,用戶可以在不中斷運(yùn)行代碼的情況下,允許運(yùn)行多種軟件的系統(tǒng)組件。

接口象類那樣描述屬性和方法,但是它和類不同的是,接口不能提供任何implementation。

為了正確的操作VB.NET接口實(shí)現(xiàn)多態(tài),用戶需先建立一個接口,并且通過其他的幾個類實(shí)現(xiàn)該接口。用戶可以用幾乎相同的方法調(diào)用其他對象已經(jīng)實(shí)現(xiàn)的方法。

下面這個例子就是VB.NET接口實(shí)現(xiàn)多態(tài):

 
 
 
  1. Namespace PolyNamespace  
  2. Interface Animal  
  3. Sub Move(ByRef Distance As Double)  
  4. Sub Bite(Byval What As Object)  
  5. End Interface  
  6. Class Flea  
  7. Implements animal  
  8. Public Sub bite(Byval What As 
    Object)Implements animal.bite  
  9. 'Bite something  
  10. End Sub  
  11. Sub Move(ByRef Distance AS Double)
    Implements animal.move  
  12. distance=Distance+1  
  13. End Sub  
  14. End Class  
  15. Class Dog  
  16. Implements animal  
  17. Public Sub bite(Byval What As Object)
    Implements animal.bite  
  18. 'Bite something  
  19. End Sub  
  20. Sub Move(ByRef Distance AS Double)
    Implements animal.move  
  21. distance=Distance+100  
  22. End sub  
  23. End Class  
  24. End Namespace  
  25. 'add this section to the your form  
  26. Protected Sub Button1_Click(Byval
     sender As System.Object,_  
  27. Byval e As System.EventArgs)  
  28. Dim aFlea As New Flea()  
  29. Dim anobj As Object()  
  30. Dim aDog As New Dog()  
  31. GetFood(aflea,anobj)  
  32. GetFood(aDog,anobj)  
  33. End Sub  
  34. Public sub GetFood(Byval Critter
     As Animal,Byval Food As Object)  
  35. Dim dblDistance As Double  
  36. 'Code to calculate distance to food(omitted).  
  37. Critter.Move(dblDistance) 'Early bound(vtable)  
  38. Critter.Bite(Food) 'Early bound(vtable)  
  39. End Sub 

VB.NET接口實(shí)現(xiàn)多態(tài)的具體代碼編寫方式就為大家介紹到這里。


新聞名稱:VB.NET接口實(shí)現(xiàn)多態(tài)實(shí)際代碼編寫
本文來源:http://www.dlmjj.cn/article/dheiosh.html