Skip to content

抽象

一句话解释

抽象是 练习的 hiding 复杂 implementation details 后面简单, 简单-到-use 接口.

用大白话说

Abstraction means focusing on what something does rather than how it does it. You create a simple interface that hides the complex details underneath. The user of the abstraction does not need to understand the internals — they just use the interface.

例如, when you call 获取('https://api.example.com') in JavaScript, you do not need to know how HTTP requests, TCP connections, or DNS resolution work. All that complexity is abstracted away behind a single function call.

Abstraction is everywhere: functions abstract away code blocks, classes abstract away state and behavior, modules abstract away implementation, APIs abstract away entire systems. Each layer of abstraction lets you think at a higher level, ignoring lower-level details. The key is: good abstractions simplify without leaking complexity.

示例

javascript
// Abstraction: a simple function hides complex logic
function isEmailValid(email) {
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}

// The caller does not need to understand regex —
// they just use the simple function
console.log(isEmailValid("[email protected]")); // true
console.log(isEmailValid("not-an-email"));    // false

regex 复杂度是 隐藏后面简单函数. caller 只是通过 email 字符串 and 获取布尔值.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表