Abstract Data Types
An abstract data type (ADT) is a concept that defines a data type by how it interacts with the user.
For example, we can describe an integer ADT from a programmer’s perspective as follows:
- You can do arithmetic operations on them (add, subtract, multiply, and divide).
- Integers can only be whole numbers.
- In many programming languages, integers can be assigned to variables.
- You can perform logical operations on them. For example, you can test whether one integer is greater than or equal to another integer.
ADTs don’t specify how the data type is implemented. That’s where the abstract in ADT comes from. ADTs focus only on how the data type interacts with the user.
Here’s another example: a list ADT. What characteristics do we want a list ADT to have? Ideally, a list ADT could:
- Store elements of one or more data types.
- Write or modify elements at a particular position.
- Read an element from a particular position.
- Insert or remove elements.
- Count the number of elements in the list.
How the programmer chooses to implement a list ADT is up to them. As long as it can do the above, it qualifies as a list.
Written on March 14, 2021