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

Implementation

Only three functions need to be implemented to complete the definition of the Object class. These are shown in Program gif.

   program4614
Program: Object Class Member Function Definitions

The Object class destructor is trivial. Since there are no member variables, nothing remains to be cleaned up. It is necessary to define the destructor in any event. As explained above, the destructor needs to be virtual and because in C++ there is no such thing as a pure virtual destructor.

The implementation of the IsNull member function is trivial. It simply returns the Boolean value false.

The Compare member function makes use of run-time type information  to ensure that the CompareTo member function is only invoked for objects which are of the same class. For objects which are not instances of the same class, the before function is used to order those objects based on their types. The C++ run-time library provides an implementation for the before function which returns true if the left hand type precedes the right hand type in the implementation's collation order.


next up previous contents index

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