Abstract Data Types
An Abstract Data Type (ADT) involves two components: (1) the data that are being stored and manipulated and (2) the methods and operations that can be performed on that data. For example, an int is an ADT. The data are the integers ranging from some MIN_INT to some MAX_INT. The operations are the various integer operations: addition, subtraction, multiplication, and division. These operations prescribe the ways that ints can be used. There are no other ways to manipulate integers.
Moreover, in designing an ADT, it’s important to hide the implementation of the operations from the users of the operations. Thus, our programs have used all of these integer operations on ints, but we have no real idea how they are implemented—that is, what exact algorithm they use.
Objects can be designed as ADTs, because we can easily distinguish an object’s use from its implementation. Thus, the private parts of an object—its instance variables and private methods—are hidden from the user while the object’s interface—its public methods—are available. As with the integer operators, the object’s public methods prescribe just how the object can be used.
Abstract Containers
Abstraction provides a useful way to conceptualize and design data structures. Consider a list. What kinds of lists can you think of? You might think of grocery lists, todo lists, quest lists, best sellers lists, and perhaps the ArrayList. What operations do these lists have in common? The basic functionality you expect from a list would be to add to the list, remove from the list, and search the list.
Test Yourself
What methods would the public interface of this abstract list include?
Note that at this point, you don’t need to know any of the private details. How will the list be stored? Where will the elements be stored? How will the list be searched? Note that there are several different algorithms that could be used to answer each of these questions. However, this is the point of abstraction! The implementation details are left to the developer (which will be you, later!). But the interface can be specified with a generalized idea of the behavior you expect from the data structure.
The following sections will look at several concrete examples of how these interfaces can be used.
Abbreviated ADT. The specification of a data type within some language, independent of an implementation. The interface for the ADT is defined in terms of a type and a set of operations on that type. The behavior of each operation is determined by its inputs and outputs. An ADT does not specify how the data type is implemented. These implementation details are hidden from the user of the ADT and protected from outside access, a concept referred to as encapsulation.
An interface is a class-like structure that only contains method signatures and fields. An interface does not contain an implementation of the methods or any data members.