< previous page page_839 next page >

Page 839
4.6 + sqrt(x)
we depend only on the function's specification, a written description of what it does. We can use the function without having to know its implementation (the algorithms that accomplish the result). By invoking the sqrt function, our program is less complex because all the details involved in computing square roots are absent.
Abstraction techniques also apply to data. Every data type consists of a set of values (the domain) along with a collection of allowable operations on those values. In Chapter 14, we described data abstraction as the separation of a data type's logical properties from its implementation details. Data abstraction comes into play when we need a data type that is not built into the programming language. We can define the new data type as an abstract data type (ADT), concentrating only on its logical properties and deferring the details of its implementation.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Abstract Data Type A data type whose properties (domain and operations) are specified independently of any particular implementation.
As with control abstraction, an abstract data type has both a specification (the what) and an implementation (the how). The specification of an ADT describes the characteristics of the data values as well as the behavior of each of the operations on those values. The user of the ADT needs to understand only the specification, not the implementation, in order to use it. Here's a very informal specification of a list ADT:
TYPE
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
IntList
DOMAIN
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Each IntList value is a collection of up to 100 separate integer numbers.
OPERATIONS
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Insert an item into the list.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Delete an item from the list.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Search the list for an item.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Return the current length of the list.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Sort the list into ascending order.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Print the list.
Notice the complete absence of implementation details. We have not mentioned how the data might actually be stored in a program (for example, in an array) or how the operations might be implemented. Concealing the im-

 
< previous page page_839 next page >