Examples of Concrete and Abstract Data Types:
-
The
MouseEvent
data type defined by Racket is a concrete data type.You know its values are strings, and you know the possible values of those strings (such as
"button-down"
). You are allowed to rely upon that representation when you write functions that process aMouseEvent
. -
The structure types you designed and defined
near the beginning of the semester
were concrete types.
You knew the field names of each structure, and you relied upon that knowledge in your observer templates and in functions that used those observer templates.
-
The
char[]
type of Java is concrete.You know the values of that type are represented as 0-origin arrays of fixed length, and you know every element of those arrays is represented by a 16-bit integer.
-
The
List
type of Java is abstract.You do not know how values of that type are represented. A value of the
List
type might be aLinkedList
, anArrayList
, aCopyOnWriteArrayList
, or an object of some class defined by the course staff whose representation will never be revealed to you. Methods that are passed aList
argument can observe properties of that argument by calling the methods listed by theList
interface, but they cannot rely on the representation of the argument.Note also that, in general, you do not even know whether a value of the
List
type is mutable. All of the methods listed by theList
interface that are capable of modifying a list's state are optional. You cannot use optional methods unless a precondition or some other invariant tells you the methods are available for you to use.