|
|
|
|
|
Abstract Data TypesConstructors, destructors and manipulation functions.In this article, we shall be discussing the concept of abstract data types – those pieces of code which embody a set of data.
IntroductionIn 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 ADTsAn ADT usually has several components:
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 PracticeMost 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:
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. ConclusionUnderstanding 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 LinksMailing ListStay 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.
|
|
|
|