Classes to Produce ADTs
-
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.
-
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.
-
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.
-
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.
-
The interface of the ADT should be all one needs to read in order to use the ADT.
-
The implementation of the ADT tells how this interface is realized as C++ code.
-
The implementation of the ADT consists of the private member variables and the definitions of both the public and private member functions.