SWE 4743 Abstract Data Types Richard Gesick
SWE Abstraction Classification, generalization, and aggregation are the basic ways we have of structuring information. When they are repeatedly applied to objects, hierarchies of new objects are formed.
SWE ADT The idea of an ADT is to separate the notions of specification (what kind of thing we're working with and what operations can be performed on it) and implementation (how the thing and its operations are actually implemented).
SWE Specification of ADT A description of the elements that compose the data type A description of the relationships between the individual components in the data type A description of the operations we wish to perform on the components of the data type
SWE Abstract Data Types An abstract data type (ADT) is a model of a data structure that specifies: – the characteristics of the collection of data – the operations that can be performed on the collection It’s abstract because it doesn’t specify how the ADT will be implemented. A given ADT can have multiple implementations
SWE Benefits of using ADTs Code is easier to understand (e.g., it is easier to see "high-level" steps being performed, not obscured by low-level code). Implementations of ADTs can be changed (e.g., for efficiency) without requiring changes to the program that uses the ADTs. ADTs can be reused in future programs.
SWE Levels of Abstraction in Specifying data
SWE Preconditions, postconditions, and invariants preconditions, that specify when an operation may be executed; postconditions, that relate the states of the ADT before and after the execution of each operation; and invariants, that specify properties of the ADT that are not changed by the operations.
SWE Consider an Array ADT What are the pre and post conditions for the following operations? Construct Destroy Retrieve Assign
SWE Construct Precondition: An uninitialized Array object PostCondition: The array object has been allocated sufficient storage to store its associated data items although no specific values have been stored in the array
SWE Destroy Precondition: An Array object has been previously allocated PostCondition: All storage allocated for the array object is deallocated
SWE Retrieve Preconditions: –An Array object has been previously created; – i is a valid index PostCondition: The value associated with the index i in the array object is returned
SWE Assign Preconditions: –An Array object has been previously created; – i is a valid index –val is a specified value for an array datum PostCondition: The Array object has val associated with index i. val is stored at index i in the array
SWE Array ADT specifications Description of Elements: the only restriction is that all the elements are of the same data type Relationships between individual components: specified as position determined by index Operations: Specified with a set of pre and post conditions