Chapter 2 Building Abstraction with Data
compound data object
data abstraction: isolating the parts of a program that deal with how data objects are used
key points: closure, conventional interface
2.1 Introduction to Data Abstraction
Procedure Abstraction: separate the way the procedure would be used from the details of how the procedure would be implemented in terms of more primitive procedures.
Data Abstraction: isolate how a compound data object is used from the details of how it is constructed from more primitive data objects.
Selectors / Constructors
2.1.1 Arithmetic Operations for Rational Numbers
Pairs
cons car cdr
2.1.2 Abstraction Barriers
--- Programs that use rational numbers ---
Rational numbers in problem domain
--- add-rat, sub-rat ... ---
Rational numbers as numerators and denominators
--- make-rat numer demom ---
Rational numbers as pairs
--- cons car cdr ---
2.1.3 What Is Meant by Data?
Data: defined by some collection of selectors and constructors, together with specified conditions that these procedures must fulfill in order to be a valid representation.
example:
x = make-rat(n, d)
(number x)/(denom x) = n/d
Procedural presentation of data play a central role in our programming repertoire. This style of programming is often called message passing.
2.1.4 Extended Exercise: Interval Arithmetic
2.2 Hierarchical Data and the Closure Property
Closure Property of cons: an operation for combining data objects satisfies the closure property if the results of combining things with that operation can themselves be combined using the same operation.
2.2.1 Representing Sequences
2.2.2 Hierarchical Structures
2.2.3 Sequences as Conventional Interfaces
Modular construction is a powerful strategy for controlling complexity in engineering design
enumerate / filter / map / accumulate
2.2.4 Example: An picture language
2.3 Symbolic Data
... ...
2.4.3 Data-Directed Programming and Additivity
dispatch on type: check the type of a datum and calling an appropriate procedure. problem: must know about all the different representations.
data-directed programming
本章探讨了如何使用数据建立抽象,包括复合数据对象、数据抽象的关键点(如封闭性和传统接口)。介绍了选择器和构造器的概念,通过理数运算、对偶和闭合属性展示了数据抽象。此外,还讨论了层次数据、序列作为常规接口以及符号数据的应用,如数据定向编程。
277

被折叠的 条评论
为什么被折叠?



