'## CBaseWindow ##
'This is the most basic "building block" of the system demonstrated here.
'It is designed as a layout of functions that all subsequent classes should use.
'If you notice there are only 4 generic functions, a derived class can add as many
'public or private variables/functions that it may want. It can also choose to have its
'own Initialise/OneFrameUpdate/ProcessMessage/Terminate functions, overloaded if necessary
'but if it does not implement custom versions of these functions, any code that attempts to
'call the function will not cause an error, instead it will fall back onto this default class
'structure.
'
'These basic functions shouldn't do anything complicated, rather they just handle a simple default
'case and make sure it doesn't break ;)
Class CBaseWindow
'this function should be used to create any references, initialise any data, configure
'the window etc...
Public Overridable Function Initialise() As Boolean
Return True
End Function
'this function could be used to render graphics, update animations, variables etc...
Public Overridable Function OneFrameUpdate() As Boolean
Return True
End Function
'this function could handle user-input, eg, Mouse and keyboard input...
Public Overridable Function ProcessMessage() As Boolean
Return True
End Function
'this function should clear up any allocated memory/objects and save any data
'needed later on...
Public Overridable Function Terminate() As Boolean
Return True
End Function
End Class
'## CMainWindow ##
'This window is derived from our base class, but only implements
'three of the four base functions (not ProcessMessage), should an application
'define a class of this type and then call CMainWindow.ProcessMessage() the code
'in the CBaseWindow.ProcessMessage() will be executed (without any warnings/errors)...
Class CMainWindow
'this next line indicates that we're wanting to use the functions
'included as part of the CBaseWindow class.
Inherits CBaseWindow
Public Overrides Function Initialise() As Boolean
'This is a custom initialisation function, we could put whatever we want in here
'and it'll be executed instead of the equivelent CBaseWindow.Initialise() code...
Return True
End Function
Public Overrides Function OneFrameUpdate() As Boolean
Return True
End Function
Public Overrides Function Terminate() As Boolean
Return True
End Function
'Note that the next two functions are NOT
'included in the Base class, but are still perfectly valid...
Public Sub StartANewGame()
End Sub
Private Sub LoadSomeData()
End Sub
End Class
Module modMain
Sub Main()
Dim MyWindow As New CMainWindow()
MyWindow.Initialise() 'Calls the customised initialisation function
MyWindow.ProcessMessage() 'calls the default ProcessMessage() found in the Base Window
MyWindow.Terminate() 'calls the custom termination function.
CallTerminate(MyWindow) 'passes the derived class as an instance of its base class...
System.Threading.Thread.Sleep(2000)
End Sub
'this sub may be taking a CBaseWindow parameter, but it'll accept
'any other classes that are derived FROM the CBaseWindow class.
'Inside this function any calls made are still going to be handled the
'same as if we do it manually through the derived class! ie, in this example
'TheWindow.Terminate() actually calls the custom termination function written into
'the CMainWindow class, and NOT the one in CBaseWindow...
Private Sub CallTerminate(ByRef TheWindow As CBaseWindow)
TheWindow.Terminate()
End Sub
End Module
|