In 1.1.8, we noted that a procedure used as an element in
creating a more complex procedure could be regarded not only as a collection of
particular operations but also as a procedural abstraction. That is, the
details of how the procedure was implemented could be suppressed, and the
particular procedure itself could be replaced by any other procedure with the
same overall behavior. In other words, we could make an abstraction that would
separate the way the procedure would be used from the details of how the
procedure would be implemented in terms of more primitive procedures. The
analogous notion for compound data is called
data abstraction. Data
abstraction is a methodology that enables us to isolate how a compound data
object is used from the details of how it is constructed from more primitive
data objects.
在 1.1.8 节中,我们曾指出,用作构造复杂过程之元素的一个过程,不仅可以被视为一组特定操作的集合,还可以被视为一种过程性抽象 (procedural abstraction)。也就是说,过程的实现细节可以被抑制,而该过程本身可以被任何具有相同总体行为的其他过程所替代。换言之,我们可以构造一种抽象,将过程的使用方式与过程借助更基本的过程加以实现的细节分离开来。对于复合数据,与之类比的概念称为数据抽象 (data abstraction)。数据抽象是一种方法论,它使我们能够将复合数据对象的使用方式与其由更基本的数据对象构造的细节相互隔离。
The basic idea of data abstraction is to structure the programs that are to use
compound data objects so that they operate on “abstract data.” That is, our
programs should use data in such a way as to make no assumptions about the data
that are not strictly necessary for performing the task at hand. At the same
time, a “concrete” data representation is defined independent of the programs
that use the data. The interface between these two parts of our system will be
a set of procedures, called
selectors and
constructors,
that implement the abstract data in terms of the concrete representation. To
illustrate this technique, we will consider how to design a set of procedures
for manipulating rational numbers.
数据抽象的基本思想是:将使用复合数据对象的程序构造为操作"抽象数据"的形式。也就是说,程序使用数据的方式不应对数据做任何超出当前任务所必需的假设。与此同时,一种"具体的"数据表示方式被独立于使用该数据的程序加以定义。系统这两部分之间的接口由一组过程构成,称为选择函数 (selectors) 和构造函数 (constructors),它们以具体表示为基础实现抽象数据。为了说明这一技术,我们将考察如何设计一组用于操作有理数的过程。