Trừu tượng hóa và Thiết kế Chương trình
Đã giới thiệu| English | Ý nghĩa |
|---|---|
| abstraction/əbˈstrækʃn/ | trừu tượng hóa |
| procedural abstraction/prəˈsiːdʒərəl əbˈstrækʃn/ | trừu tượng hóa thủ tục |
| method decomposition/ˈmeθəd ˌdiːkɒmpəˈzɪʃn/ | phân rã phương thức |
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.
Giao diện hay triển khai?
Abstraction che giấu cách làm đằng sau một cái gì đó đơn giản. Sắp xếp từng mục.
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.
Abstraction được mô tả tốt nhất là...
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Abstraction che giấu cách một thứ gì đó hoạt động để bạn có thể sử dụng cái nó làm.
Procedural abstraction cho phép bạn sử dụng một method bằng cách...
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Bạn gọi nó bằng tên và đầu vào, không phải bởi các chi tiết nội bộ của nó.
Chia nhỏ một vấn đề lớn thành các hành vi có tên nhỏ hơn (methods) được gọi là method ___ (một từ).
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Method decomposition chia công việc thành các methods tập trung.
Khi thiết kế một class, bạn nên quyết định điều gì?
Độ khó 2/5 · 140 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Thiết kế là về dữ liệu + hành vi, được nhóm hợp lý — không phải địa chỉ.
Thiết kế chương trình tốt giúp chương trình dễ xây dựng, đọc và tái sử dụng hơn.
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Đó là lợi ích của trừu tượng hóa và phân rã.