Classes to Produce ADTs

  1. A data type consists of a collection of values together with a set of basic operations defined on these values. For example, int is a data type consisting of whole numbers and operations, such as +, -, *, and %, that operate on them.

  2. A data type is called an abstract data type (ADT) if a programmer who uses the type does not need to know any of the details about how the values and operations for that type are implemented.

  3. One way to implement an ADT in C++ is to define a class
    • with all member variables private and
    • with the operations implemented as public member function.
    • Any auxiliary helping functions that are only needed in the definitions of other member functions should be private.
    • Details how these public member functions can be used must be included with the prototypes of the functions.

  4. The interface of an ADT describes how the ADT can be used. When an ADT is defined as a class, the interface consists of the public member functions of the class along with comments describing how these member functions can be used.

  5. The interface of the ADT should be all one needs to read in order to use the ADT.

  6. The implementation of the ADT tells how this interface is realized as C++ code.

  7. The implementation of the ADT consists of the private member variables and the definitions of both the public and private member functions.