本文介绍了可有人解释MustOverride?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释不是MustOverride做,但为什么要用它?难道是揭露功能?

Can someone explain not what MustOverride does, but why use it? Is it to expose the function?

我有两个班,第一个(RoomFactory);

I have two classes, the first (RoomFactory);

Public MustInherit Class RoomFactory : Inherits baseFactory
Private _roomid As Integer = 0
Private _roomname as String = ""

Public Sub New()

End Sub

Public Sub New(ByVal roomid As Integer, ByVal roomname As String)
    Me.RoomId = roomid
    Me.RoomName = roomname
End Sub

Public MustOverride Function CreateRoom(ByVal roomdetails As RoomFactory) As Integer
Public MustOverride Function IsRoomAvailable(ByVal roomdetails as RoomFactory) As Boolean
// .. properties removed for brevity .. //

第二类(室)

Second class (Room)

Public Class Room : Inherits RoomFactory
    Public Function CreateRoom(ByVal roomdetails As RoomFactory) As Integer
        Return 0
    End Function
    Public Function IsRoomAvailable(ByVal roomdetails As RoomFactory) As Boolean
        Return False
    End Function
End Class

首先,我认为这是正确的,但想任何建议,否则 - 性能等,但我想主要的问题是 - 为什么使用MustOverride

Firstly, I think this is right, but would like any advice to the otherwise - performance etc. But I guess the primary question is - why use the MustOverride?

请点击这里原谅我的无知。

Please excuse my ignorance here.

推荐答案

它是如此,你可以提供一个基类常见的功能,但力派生类来实现功能本身的特定位。

It's so that you can provide common functionality in a base class, but force derived classes to implement specific bits of functionality themselves.

在你的工厂的情况,我会建议使用的界面,而不是一个抽象类,但在其他情况下,这是有道理的。 System.Text.Encoding 是一个抽象类的一个很好的例子,如的System.IO.Stream

In your factory situation I would suggest using an interface rather than an abstract class, but in other cases it makes sense. System.Text.Encoding is a good example of an abstract class, as is System.IO.Stream.

这篇关于可有人解释MustOverride?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 03:46