next up previous contents
Next: Sorts and Types of Up: Algebraic Specification of Abstract Previous: Introduction

Specification of Abstract Data Types

In the early days, the computer scientist was very much pre-occupied with machine-oriented problems of storage and data representation - concrete details. The realisation that data types are not simply a set of values but consist also of a collection of operations which act upon the values led to an awareness of the importance of data abstraction for both programming language design and the specification of software systems. In particular, the importance of separating the specification of an abstract data type from its representation has long been recognised with the resulting benefits for the modularisation of software, software reusability and data integrity. This concept is supported by a number of programming languages including Ada and Modula-2. In the case of Modula-2, a definition module provides information about the syntax of an abstract data type while the representation of the data type and the implementation of its associated operations are provided by a corresponding implementation module. The corresponding structures in Ada are provided by the package header (specification) and package body respectively.

As an illustration, consider the specification of an unbounded stack. The stack is an example of a LIFO (last-in-first-out) structure which has many applications in computer science. Yet it is important to realise that the characteristic behaviour of a stack is quite independent of the data it manipulates or the representation of the stack itself. It is the collection of operations which can be performed upon a stack that defines its behaviour. In particular, data values can be pushed onto the top of a stack or popped and retrieved from the top of a non-empty stack so that the behaviour of a stack can be described in terms of the following operations :

As a prelude to the development of an algebraic specification for the stack, it will be instructive to look briefly at how such an abstract data type might be specified in a high-level imperative language such as Modula-2. This will serve not only to introduce some basic terminology and notation which will be used in the subsequent discussion on algebraic specifications, but will also help to put the algebraic approach into sharper perspective. Those not familiar with Modula-2, but with a working knowledge of any procedural language such as Fortran, Pascal or C will find no difficulty in understanding the specification.

With Modula-2, the user of an abstract data type is presented with a signature in the form of a DEFINITION MODULE which specifies the syntax of the components of an abstract data type by means of formal Modula-2 declarations (such as TYPE and PROCEDURE statements). The DEFINITION MODULE presents an external interface to users of the abstract data type and so must provide a clear and precise description of the resources available. In other words, the DEFINITION MODULE must adequately describe ``what the abstract data type does''. For a stack of natural numbers (non-negative integers corresponding to the pre-defined data type CARDINAL in Modula-2) with the operations described above, the DEFINITION MODULE is given in Fig. 8.1.


  
Figure 8.1: Modula-2 signature for an unbounded stack
\begin{figure}
\begin{tex2html_preform}\begin{verbatim}DEFINITION MODULE Stacks;...
... otherwise *)END Stacks.\end{verbatim}\end{tex2html_preform}
\par\end{figure}

The following points should be noted :



 
next up previous contents
Next: Sorts and Types of Up: Algebraic Specification of Abstract Previous: Introduction
Lee McCluskey
2002-12-18