< previous page page_915 next page >

Page 915
SOFTWARE ENGINEERING TIP
Inheritance and Accessibility
With C++, it is important to understand that inheritance does not imply accessibility. Although a derived class inherits the members of its base class, both private and public, it cannot access the private members of the base class. Figure 16-5 shows the variables hrs, mins, and secs to be encapsulated within the Time class. Neither external client code nor ExtTime member functions can refer to these three variables directly. If a derived class were able to access the private members of its base class, any programmer could derive a class from another and then write code to directly inspect or modify the private data, defeating the benefits of encapsulation and information hiding.

Specification of the ExtTime Class
Below is the fully documented specification of the ExtTime class. Notice that the preprocessor directive
#include time.h
is necessary for the compiler to verify the consistency of the derived class with its base class.
//******************************************************************
// SPECIFICATION FILE (exttime.h)
// This file gives the specification of an ExtTime abstract data
// type.  The Time class is a public base class of ExtTime, so
// public operations of Time are also public operations of ExtTime.
//******************************************************************
#include time.h

enum ZoneType {EST, CST, MST, PST, EDT, CDT, MDT, PDT};

 
< previous page page_915 next page >