TheZoo
property. You can get a reference to the ZooKeeper via the Zoo.TheKeeper property.
CHAPTER 6 n INTERFACES 108
nNote The Singleton design pattern is one of the most well-known and widely used design patterns. Essentially,
the pattern allows only one instance of a type to exist at any one time. Many still argue about the best
way to implement it, but in general, some Private Shared variable within the type itself is lazily initialized to
the single instance at the point of first access. The Zoo class does that, since its constructor is Private, and
the only instance that ever gets created is stored in the instance variable and initialized when the class is
first loaded.
This initial design defines ZooDweller as a MustInherit class that implements a method,
EatSomeFood, which calls a MustOverride method, EatTheFood. (This is an example of the Non-
Virtual Interface (NVI) pattern, described in Chapter 14.)
The ZooDweller class does, in fact, define a contract even though it is not an interface.
The contract, as written, states that any class that inherits from ZooDweller must implement
EatSomeFood(). Any code that uses a ZooDweller instance can be guaranteed that this method
is supported.
nNote An interface is not required in order to define a contract.
Pages:
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200