swe 4743 abstract data types richard gesick. swe 4743 2-14 abstraction classification,...
Post on 23-Dec-2015
217 Views
Preview:
TRANSCRIPT
SWE 4743
Abstract Data Types
Richard Gesick
SWE 4743 2-14
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 4743 3-14
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 4743 4-14
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 4743 5-14
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 4743 6-14
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 4743 7-14
Levels of Abstraction in Specifying data
SWE 4743 8-14
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 4743 9-14
Consider an Array ADT• What are the pre and post conditions for
the following operations?• Construct• Destroy• Retrieve• Assign
SWE 4743 10-14
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 4743 11-14
Destroy• Precondition: An Array object has been
previously allocated• PostCondition: All storage allocated for
the array object is deallocated
SWE 4743 12-14
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 4743 13-14
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 4743 14-14
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
top related