First, consider the assumptions that you can make here. Let??™s say that this
Zoo can have only one ZooKeeper. Second, let??™s assume that you can model the locations within
this Zoo by using a simple two-dimensional Point structure. It starts to look as though you can
model this system by the following code:
Imports System.Collections.ObjectModel
Namespace CityOfShanoo.MyZoo
Public Structure Point
Public x As Double
Public y As Double
End Structure
CHAPTER 6 n INTERFACES 107
Public MustInherit Class ZooDweller
Sub EatSomeFood()
EatTheFood()
End Sub
Protected MustOverride Sub EatTheFood()
End Class
Public NotInheritable Class ZooKeeper
Public Sub SendFlyCommand(ByVal dest As Point)
'Get creatures to fly
End Sub
End Class
Public NotInheritable Class Zoo
Private Shared instance As Zoo = New Zoo()
Private keeper As ZooKeeper
Private creatures As Collection(Of ZooDweller)
Private Sub New()
creatures = New Collection(Of ZooDweller)()
keeper = New ZooKeeper()
End Sub
Public Shared ReadOnly Property TheZoo() As Zoo
Get
Return instance
End Get
End Property
Public ReadOnly Property TheKeeper() As ZooKeeper
Get
Return keeper
End Get
End Property
End Class
End Namespace
Since only one zoo can exist in the CityOfShanoo, the Zoo is modeled as a Singleton object,
and the only way to obtain the instance of the one and only Zoo is through the Zoo.
Pages:
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199