Абстракция и проектирование программ
Введено| English | Значение |
|---|---|
| abstraction/əbˈstrækʃn/ | Абстракция |
| procedural abstraction/prəˈsiːdʒərəl əbˈstrækʃn/ | Процедурная абстракция |
| method decomposition/ˈmeθəd ˌdiːkɒmpəˈzɪʃn/ | Метод декомпозиции |
Hiding the details
- Abstraction 抽象 means hiding details to focus on the main idea.
- You drive a car by the steering wheel and pedals — not by knowing the engine's internals.
- In code, abstraction lets you use something by what it does, not how.
- It's the single most important idea for managing large programs.
Procedural abstraction
- Procedural abstraction 过程抽象 packages a behavior into a method you call by name.
- Once written,
average(scores)is used for its result — the code inside is hidden. - The method name and parameters (its interface) are all a caller needs.
- This is exactly how you use library methods like
Math.sqrt.

Decomposing a program into modules and sub-modules
Method decomposition
- Break a big problem into smaller behaviors, each its own method — method decomposition 方法分解.
- "Process an order" →
checkStock(),chargeCard(),ship(). - Small, named methods are easier to write, test, and reuse.
- The main method then reads like a high-level summary.
Planning a class
- To design a class, decide what data it holds and what behaviors it offers.
- A
Studenthas data (name, scores) and behaviors (addScore,average). - Good design groups related data and behavior together.
- Planning first makes a program easier to build, read, and reuse.
Интерфейс или реализация?
Абстракция скрывает «как» за простым «что». Отсортировать каждый элемент.
Abstraction is about the interface, not the implementation. A caller of average(scores) needs only its name, inputs, and result — never the loop inside. Design each method to do one clear job (method decomposition); a method that does five unrelated things is hard to name, test, and reuse. Plan a class as data + behaviors before writing code.
Designing a Student class:
- Data: the student's name and a list of scores.
- Behaviors:
addScore(s),average(),highest(). - A caller uses
student.average()for its result — the calculation is hidden inside.
Abstraction hides details to focus on the main idea; procedural abstraction lets you use a method by what it does, not how. Method decomposition breaks a big problem into small, named behaviors. Design a class by deciding its data and behaviors — good design makes code easier to build, read, and reuse.
Абстракцию лучше всего описывает...
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
Абстракция скрывает то, как что-то работает, чтобы вы могли использовать то, что оно делает.
Процедурная абстракция позволяет использовать метод путем...
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
Вы вызываете его по имени и входным параметрам, а не по его внутреннему устройству.
Разделение большой задачи на меньшие именованные поведения (методы) называется методом ___ (одно слово).
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
Декомпозиция метода разделяет работу на специализированные методы.
При проектировании класса, что вы должны определить?
Сложность 2/5 · 140 монет + небольшой бонус за первое выполнение сегодня
Проектирование касается данных + поведения, логически сгруппированных — не адресов.
Хорошее проектирование программы делает её проще в разработке, чтении и повторном использовании.
Сложность 1/5 · 100 монет + небольшой бонус за первое выполнение сегодня
Это и есть отдача от абстракции и декомпозиции.