当前位置:编程学习 > VB >>

VB.Net中文教程(4) 易做图对象关系(3)

 

 

Me.Create()

   End Sub

........

 

也能写为:

Class MyRoom

   Inherits Room

   Private rd As Desk

  

   Public Sub New()

       rd = New Desk()

       Me.Create()

   End Sub

........

 

只要确保Desk类别的指令──

     dSize = Room.GetMother().GetSize() * 0.18

 

是在MyRoom类别的指令──

     rSize = 100

 

之后执行即可了。

   上述的子对象是透过Shared 程序来取得母对象的参考值﹐然后才跟母对象沟通。如果不透过Shared程序,也可以采取下述方法:

 

ex04.bas

Imports System.ComponentModel

Imports System.Drawing

Imports System.WinForms

----------------------------------------------------

Class Room

   Protected rSize As Double

  

   Public Overridable Sub Create()

   End Sub

   Public Function GetSize() As Double

       GetSize = rSize

   End Function

End Class

 

Class Desk

   Protected dSize As Double

   Protected myMother As Room

  

   Public Sub Create(ByVal mo As Room)

       myMother = mo

       dSize = myMother.GetSize() * 0.18

   End Sub

   Public Function GetSize() As Double

       GetSize = dSize

补充:软件开发 , Vb ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,