Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

The NullObject Singleton Class

 

The declaration of the NullObject class is given in Program gif. The NullObject class is a concrete class derived from the Object abstract base class. The NullObject class is also a singleton  class. I.e., it is a class of which there will only ever be exactly one instance. The one instance is in fact a static member variable of the class itself. In order to ensure that no other instances can be created, the default constructor is declared to be a private member function. The static member function Instance returns a reference to the one and only NullObject instance.

   program4647
Program: NullObject Class Definition




next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.