Supose基類如何在VB.NET中從派生類中的基類中禁用屬性或方法?
Public Class airplane
Private var_num_seats As Integer
Private var_num_engines As Integer
Protected Property num_seats As Integer
Get
Return var_num_seats
End Get
Set(ByVal param_num_seats As Integer)
var_num_seats = param_num_seats
End Set
End Property
Protected Friend Property num_engines As Integer
Get
Return var_num_engines
End Get
Set(ByVal param_num_engines As Integer)
var_num_engines = param_num_engines
End Set
End Property
Protected Friend Sub take_off()
'Do take off tasks
End Sub
Protected Friend Sub start_engines()
'start each engine
End Sub
End Class
和子類
Public Class glider
Inherits airplane
Private var_towed As Boolean
Private var_glide_rate As Double
Public ReadOnly Property towed As Boolean
Get
Return var_towed
End Get
End Property
Public ReadOnly Property glide_rate As Double
Get
Return var_glide_rate
End Get
End Property
Public Sub to_glide()
'do gliding
End Sub
End Class
很顯然,我不希望這個類滑翔機在方法「start_engines」既沒有財產「num_engines」。否則,其他兒童班可能有。我怎麼能在孩子課上壓制這些屬性和方法,而不僅僅是忽略(如果可以的話)?
謝謝!
多個驚歎號是患病心靈的明確標誌。 – CodesInChaos 2011-04-07 13:28:33
我在接電話的時候非常興奮;) – tster 2011-04-07 13:29:58
+0.49。任何飛機都應該能夠'start_engines()',而不用擔心操作不被支持,因爲它是界面的一部分。 (注意,雖然''start_engines()''不一定必須做任何事情,除了大概讓飛機準備好移動。沒有引擎啓動的滑翔機,它可以返回。)同樣,'num_engines '總是可以返回0.(它應該是真正的只讀或'私人設置')飛機不應該能夠改變它們的引擎數量。)但是,如果滑翔機的使用方式與飛機不同,則不應該從另一個繼承。 – cHao 2011-04-07 13:35:57