< previous page page_871 next page >

Page 871
public, a client could store incorrect values (such as January 35, 1956) into the public data, compromising the correct behavior of the ADT.
Print the date: This operation prints the date on the standard output device in the following form:
January 12, 1996
Compare two dates: This operation compares two dates and determines whether the first one comes before the second one, they are the same, or the first one comes after the second one. To indicate the result of the comparison we define an enumeration type with three values:
enum RelationType {BEFORE, SAME, AFTER};
Then we can code the comparison operation as a class member function that returns a value of type RelationType. Here is the function prototype:
RelationType ComparedTo( /* in */ DateType otherDate ) const;
Because this is a class member function, the date being compared to otherDate is the class object for which the member function is invoked. That is, the following client code tests to see whether date1 comes before date2.
DateType date1;
DateType date2;
 .
 .
 .

if (date1.ComparedTo(date2) == BEFORE)
    DoSomething();
Increment the date by one day: This operation advances the date to the next day. For example, given the date March 31, 1997, this operation changes the date to April 1, 1997.
We are now almost ready to write the C++ specification file for our DateType class. However, the class declaration requires us to include the private partthe private variables that are the concrete data representation of the ADT. Choosing a concrete data representation properly belongs in the ADT implementation phase, not the specification phase. But to satisfy the

 
< previous page page_871 next page >