Can someone explain not what MustOverride does, but why use it? Is it to expose the function?
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
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.
In your factory situation I would suggest using an interface rather than an abstract class, but in other cases it makes sense.
System.Text.Encodingis a good example of an abstract class, as isSystem.IO.Stream.