Abstract Data Types
Abstract data types are a way of dealing with specific data structures without
losing sight of the problem. All too often the way a particular data structure
is encoded in software (for example as an array) is scattered throughout
the source code. Then when a change is required modifications must be made
throughout the whole source code.
An abstract data type effectively embeds the data within a module. The actual
interface can be extremely simple. One of the most simple is two routines,
one called light_on the other light_off.
The whole point is that you can embed within a module the workings of a
particular data object, and access this in more of a way you would interact
with real world things.
For instance, take a data structure that contains the text for a book. This
is only one part of the program. Now say you want to turn to the index,
or turn back a page. To encode all the operations to do this as in-line
code complicates the issue. Instead we create several routines to manipulate
the book:
turn_back_page, turn_forward_page, go_to_index, go_to_content.
Then several more that access the data such as
read_titles, read_page.
The data structure is PRIVATE to the MODULE - that is NOTHING apart from
the access routines is allowed to alter or read the data structure.
We now know that:
Please note, you already work with ADT's. For instance the file system
is a type of ADT. How many times do you have to work with the disk directory
structure? Or the head position. The whole ADT makes it quite a bit more
simpler.
Also, it is worth noting that you can stack ADT systems on top of each other.
For instance, low level serial routines might put and get a byte. The next
level might handle sending and receiving strings, the next level may open
and close concurrent streams.
These three levels form, at the top, a very flexible interface. If at all
possible you should avoid cross level calls - in this way the hierarchical
structure of your program is maintained.
Some More ADT Examples
An elevator
File
Fuel Tank
Nuclear reactor cooling system