An abstract data type (ADT) is a name (the type-name) and a list of the actions that can be performed on it.
For example, consider the INTEGER_STACK ADT. The actions on it are:
In C, the ADT type-name is defined using typedef. The actions are implemented as functions. The actions and the type-name are grouped together in a single .h header file.
/* integer stack ADT */
typedef struct int_stack * int_stack;
int_stack make_int_stack(void);
void destroy_int_stack(int_stack);
void push_int_stack(int_stack, int);
int top_int_stack(const int_stack);
void pop_int_stack(int_stack);
int is_empty_int_stack(const int_stack);
We are assuming that this ADT (and, in general all ADTs) will be heap allocated. Therefore, in C:
int_stack) will be a pointer to some structure.
make_ and destroy_;
that way I know that:
make_T(), I know it returns an
instance of ADT T.
destroy_T(), I know it is destroying an
instance of T.
T, chances
are that the functions I want to use are make_T() and
destroy_T().
We have also used some other conventions.
top_int_stack).
Using the type-name as part of the function name has two benefits:
length(). At some point they would try to integrate.
The length() functions would be multiply defined and the
integration would fail until the names were changed.
length_T_list(names), they immediately knows what
is happening, even without knowing the type of names.
push_int_stack(vals, sums), he/she knows that it is sums that
is being pushed onto vals, and not the other way around.
That is all that belongs in the header file; in particular there are no implementation details.