Data Abstraction · 数据抽象
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| complexity/kəmˈpleksɪti/ | 复杂性 | fù zá xìng |
| Data abstraction/ˈdeɪtə əbˈstrækʃn/ | 数据抽象 | shù jù chōu xiàng |
| list/lɪst/ | 列表 | liè biǎo |
| abstract data type/ˈæbstrækt ˈdeɪtə taɪp/ | 抽象数据类型 | chōu xiàng shù jù lèi xíng |
| general/ˈdʒenərəl/ | 通用 | tōng yòng |
| abstraction/əbˈstrækʃn/ | 抽象 | chōu xiàng |
| modeling/ˈmɒdəlɪŋ/ | 建模 | jiàn mó |
| model/ˈmɒdl/ | 模型 | mó xíng |
Hiding detail to manage complexity
- Real programs deal with a lot of data.
- Data abstraction 数据抽象 hides detail so we can manage complexity 复杂性.
- Instead of tracking many small pieces separately, we group them under one name.
- The most common tool for this is a list 列表.
隐藏细节以管理复杂性
- 真实程序处理大量数据。
- 数据抽象(data abstraction)隐藏细节,让我们管理复杂性(complexity)。
- 与其分别追踪许多小片,我们把它们归到一个名字下。
- 为此最常用的工具是一个列表(list)。
Use a list, or one variable? · 用列表,还是一个变量?
A list (data abstraction) is worth it when you have many similar values; a single variable is enough for one standalone value. · 当你有许多相似的值时,列表(数据抽象)是值得的;对一个单独的值,一个变量就够了。
Data abstraction helps a programmer by: · 数据抽象帮助程序员是通过:
Grouping data under one name hides needless detail. · 把数据归到一个名字下隐藏不必要的细节。
A ______ groups many values under one name, like all the marks of a class. · 一个______把许多值归到一个名字下,像一个班的所有分数。
A list is the most common abstract data type. · 列表是最常见的抽象数据类型。
Using a list makes code general: the same loop works for 5 or 500 values. · 用列表让代码通用:同样的循环适用于 5 个或 500 个值。
The code refers to the list by name, not to each value. · 代码按名字引用列表,而非每个值。
Lists group many values
- A list is an abstract data type 抽象数据类型 that groups many values under one name.
- One list
scorescan hold a whole class's marks — not a separate variable per student. - Using a list makes code more general 通用: the same code works with 5 values or 500.
- It refers to the list by name, not to each value one by one.
列表把许多值分组
- 一个列表是一个抽象数据类型(abstract data type),把许多值归到一个名字下。
- 一个列表
scores能装整个班的分数——而非每个学生一个变量。 - 用列表让代码更通用(general):同样的代码适用于 5 个值或 500 个值。
- 它按名字引用列表,而非一个一个地引用每个值。
Which are benefits of data abstraction? (Select all that apply) · 哪些是数据抽象的好处?(选出所有正确项)
One clear name beats fifty separate ones on all three counts. · 一个清晰的名字在这三方面都胜过五十个分开的名字。
Why abstraction helps
- Less repetition — you write the logic once, not once per value.
- Easier changes — add a value to the list and the same code still works.
- Fewer mistakes — one clear name is easier to get right than fifty separate names.
- This naming and grouping is the heart of abstraction 抽象.
为什么抽象有帮助
- 更少重复——你把逻辑写一次,而非每个值写一次。
- 更容易改动——往列表加一个值,同样的代码仍然有效。
- 更少错误——一个清晰的名字比五十个分开的名字更容易写对。
- 这种命名和分组是抽象(abstraction)的核心。
A model of a class stores names but ignores eye colour because: · 一个班的模型存储名字但忽略眼睛颜色,因为:
A model simplifies reality, keeping only the relevant detail. · 模型简化现实,只保留相关细节。
With a list, adding a sixth student needs no new variable and no new print line. · 用列表,加第六个学生不需要新变量,也不需要新的打印行。
Only the data changes; the same loop handles it. · 只有数据改变;同样的循环处理它。
Abstraction is modeling
- Data abstraction is a form of modeling 建模.
- A model 模型 simplifies something so we can focus on what matters.
- A list of student names models a class, ignoring details like eye colour the program never needs.
Five marks. Without abstraction: five variables mark1…mark5 and five print lines. With a list marks: one loop prints every element. If a sixth student joins, only the data changes — no new variable, no new line.
抽象就是建模
- 数据抽象是一种建模(modeling)。
- 一个模型(model)简化某物,让我们聚焦于重要的东西。
- 一个学生名字的列表为一个班建模,忽略像眼睛颜色这样程序从不需要的细节。
五个分数。 没有抽象:五个变量 mark1…mark5 和五行打印。有列表 marks:一个循环打印每个元素。如果第六个学生加入,只有数据改变——没有新变量,没有新行。
Data abstraction hides detail to manage complexity, usually with a list — an abstract data type grouping many values under one name. It makes code general (works for any size), reduces repetition and mistakes, and is a kind of modeling: keep what matters, ignore the rest.
数据抽象隐藏细节以管理复杂性,通常用一个列表——把许多值归到一个名字下的抽象数据类型。它让代码通用(适用于任何大小),减少重复和错误,并且是一种建模:保留重要的,忽略其余的。