Suite101

Abstract Data Types

Constructors, destructors and manipulation functions.

© Guy Lecky-Thompson

In this article, we shall be discussing the concept of abstract data types – those pieces of code which embody a set of data.

Introduction

In the Procedures and Functions tutorial, we looked at user defined code blocks which the programmer could use to enrich their code with easily identified sections.

We also looked at methods, as an example of an opaquely defined function that belonged to a specific object, and had meaning only within the context of that object.

Now, we shall take a small step to one side (or backwards, depending on your point of view) and contemplate Abstract Data Types (ADTs), which are almost object oriented by nature, and whose definitions are largely implementation opaque.

In other words, we do not need to understand what an ADT does, nor how it does it, in order to be able to use it; only what effect it is going to have when placed within our program.

Recognising ADTs

An ADT usually has several components:

  • The data type itself
  • A constructor and destructor
  • Manipulation functions

The purpose of the constructor is to initialize a given instance of the ADT, while the demonstrator is used to destroy it. Given that an ADT may contain multiple data objects, and a single ADT could be used to define many instances (each in a variable) these are required to enable the programmer to clean up after their program.

The manipulation functions exist to allow the programmer to interact with the ADT programmatically, without any knowledge of how the data is stored or manipulated.

Based on these principles, different implementations can be used to manipulate the data, and if a more efficient algorithm is arrived at, the underlying implementation can be changed without disrupting the program making use of the ADT.

Common ADTs in Practice

Most modern programming language textbooks refer to Lists, Stacks, Queues, Arrays and Trees as examples of ADTs. For example, a Stack implementation might contain a definition for:

  • The type of data to be stored
  • Creation of an empty stack
  • Functions to push items to the top of the stack...
  • ...or pull them off the top/bottom
  • Read/write the stack from/to files
  • etc...

Other common ATDs might include string handling. User defined ADTs in data processing applications are also quite common, as they help to model the real world data and processes.

Conclusion

Understanding ADTs is a good stepping stone between the worlds of procedural and object oriented programming languages. Once the concepts have been grasped, the reader can move on to looking at object oriented implementations of ADTs in general, and entire systems in general.

The difference between object orientation and using ADTs is that ADTs are created to solve specific data-oriented problems, and object orientation encompasses objects that manipulate ADTs, along with other objects that provide the basis for the underlying system.

Navigation Links

Mailing List

Stay informed - sign up to the mailing list!


The copyright of the article Abstract Data Types in Computer Programming is owned by Guy Lecky-Thompson. Permission to republish Abstract Data Types in print or online must be granted by the author in writing.





Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo