再学 AI
第 48 课 / ubiquitous-language
历史对照阅读 → 对照 → 问答 → 场景

历史对照:从聊天提炼领域词典

它把聊天中的领域概念规范化,记录别名、关系、歧义和示例对话,输出 UBIQUITOUS_LANGUAGE.md。

历史文件,不在当前目录

本课使用下方注明的历史提交原文,帮助理解旧文章和旧提示词。请勿据此认定当前版本仍能直接调用该名称。

还不清楚 Skill、Agent、安装和调用?先读 从零开始的6节入门课

在关系图中查看 ubiquitous-language 与其他技能的关联 →

先把必要的概念讲清楚

统一语言是让业务讨论、规格和代码使用相同概念。它不是把所有名字翻成英语,而是减少同一个词有多个意思、同一个意思有多个叫法造成的误解。

下面是老师补充的入门说明;原作者的要求保留在中英对照正文中。所有例子均为帮助理解而构造的教学情境。

domain glossary|业务领域术语表

规定项目的重要概念叫什么、指什么。domain 在这里是业务领域,不是互联网域名。课程是一组课时,课时是一份学习内容;混用会把“收藏课程”实现成“收藏某一课时”。统一语言不仅统一拼写,还统一概念边界。

schema|数据结构与约束

描述数据有哪些字段、类型、关系和限制。例如收藏包含用户 ID、课程 ID、创建时间,并要求同一用户与课程组合唯一。改 schema 可能影响存储、接口和旧数据,因此它是工程决定,不只是给变量换名字。

interface / API|接口

使用者与一项能力交互时遵循的约定,包括可调用什么、传入什么、得到什么、失败怎样表示。接口可以是程序函数,也可以是网络请求。创建收藏接口接收用户和课程信息、返回收藏结果;它不需要向调用者暴露数据库表结构。这里的接口通常不是指页面外观。 本教材涉及更广义的“接口”时,还包括错误、调用顺序和约束等使用约定;不能把接口一概等同于网络 API。

读原文,理解每一步为什么这样做

左右内容按小节对应;窄屏先中文、后英文。两种语言均完整展示,对应讲解紧接在小节之后。译文传达原文要求;老师讲解补充概念、原因、例子与适用边界。

中文译文English · 英文原文
中文译文
name: ubiquitous-language
description: "从当前对话提取 DDD 风格的统一语言术语表,指出歧义并提出规范术语,保存到 UBIQUITOUS_LANGUAGE.md。用户希望定义领域术语、建术语表、明确命名、建立统一语言,或提到领域模型/DDD 时使用。"
disable-model-invocation: true
English · 英文原文
name: ubiquitous-language
description: Extract a DDD-style ubiquitous language glossary from the current conversation, flagging ambiguities and proposing canonical terms. Saves to UBIQUITOUS_LANGUAGE.md. Use when user wants to define domain terms, build a glossary, harden terminology, create a ubiquitous language, or mentions "domain model" or "DDD".
disable-model-invocation: true
中文译文

建立一致的业务术语表

从当前对话提取业务概念,澄清并正式记录为一致词汇表,保存到本地。

English · 英文原文

Ubiquitous Language

Extract and formalize domain terminology from the current conversation into a consistent glossary, saved to a local file.

中文译文

过程

  1. 查找对话中的业务名词、动词和概念。
  2. 找出同词异义、同义多名,以及含糊或承载过多含义的词。
  3. 提出明确推荐的统一名称。
  4. 按下方格式写入工作目录的 UBIQUITOUS_LANGUAGE.md
  5. 在对话中概括结果。
English · 英文原文

Process

  1. Scan the conversation for domain-relevant nouns, verbs, and concepts
  2. Identify problems:
    • Same word used for different concepts (ambiguity)
    • Different words used for the same concept (synonyms)
    • Vague or overloaded terms
  3. Propose a canonical glossary with opinionated term choices
  4. Write to UBIQUITOUS_LANGUAGE.md in the working directory using the format below
  5. Output a summary inline in the conversation
老师讲解 · 对应上方原文 · 含教学举例

从真实对话发现概念,而不是先造词典模板

扫描领域名词、动词和关系,找同名不同义、同义不同名与过度宽泛的词。例如“用户完成了课程”可能指打开、读完或答题通过,必须澄清。

选一个规范术语后,列出应避免的别名,帮助后续材料保持一致。但规范选择应根据业务含义与使用者认知,不是只按程序员偏好改名。

代码模块名没有业务含义时不必收录。词典服务领域交流,不是全项目函数索引。

统一语言不只是统一中文名称,还要统一对象的含义

你说收藏课程,可能指整门课;AI 却把每篇技能讲解当成一门课,最终实现收藏单篇。程序可以正常运行,仍然不是你要的功能。

先定义课程是一组围绕目标组织的课时,课时是独立学习内容;再明确收藏哪种对象。关系和定义会影响规格、数据和界面,不只是文章措辞。

可以用问题检验定义:“完成一个课时,是否算完成课程?”这迫使双方明确数量关系和完成条件。比孤立背术语更有用。

原文订单、发票和履约关系属于示例业务,并非所有系统的统一规则。Invoice 的示例也不能直接当成中国税务发票规则。此历史技能写 UBIQUITOUS_LANGUAGE.md,新版可能采用 CONTEXT.md,应分清版本。

中文译文

输出格式

# 统一业务语言

## 订单生命周期

| 术语 | 定义 | 避免混用 |
| --- | --- | --- |
| 订单 Order | 客户购买一件或多件商品的请求 | Purchase、transaction |
| 发票 Invoice | 交付后向客户发出的付款请求 | Bill、payment request |

## 参与者

| 术语 | 定义 | 避免混用 |
| --- | --- | --- |
| 客户 Customer | 下订单的个人或组织 | Client、buyer、account |
| 用户 User | 系统的身份验证身份 | Login、account |

## 关系

- 每张发票恰好属于一位客户。
- 一张订单产生一张或多张发票。

## 示例对话

开发者:客户下订单时立即生成发票吗?
业务专家:不是,履约确认后才生成。分多次发运时,一张订单可能产生多张发票。
开发者:某次发运在发出前取消,就没有对应发票?
业务专家:对,发票生命周期关联履约,不是直接关联订单。

## 发现的歧义

account 曾同时表示客户与用户。客户下订单,用户是验证身份,二者并非必然相同。
English · 英文原文

Output Format

Write a UBIQUITOUS_LANGUAGE.md file with this structure:

# Ubiquitous Language

## Order lifecycle

| Term        | Definition                                              | Aliases to avoid      |
| ----------- | ------------------------------------------------------- | --------------------- |
| **Order**   | A customer's request to purchase one or more items      | Purchase, transaction |
| **Invoice** | A request for payment sent to a customer after delivery | Bill, payment request |

## People

| Term         | Definition                                  | Aliases to avoid       |
| ------------ | ------------------------------------------- | ---------------------- |
| **Customer** | A person or organization that places orders | Client, buyer, account |
| **User**     | An authentication identity in the system    | Login, account         |

## Relationships

- An **Invoice** belongs to exactly one **Customer**
- An **Order** produces one or more **Invoices**

## Example dialogue

> **Dev:** "When a **Customer** places an **Order**, do we create the **Invoice** immediately?"
> **Domain expert:** "No — an **Invoice** is only generated once a **Fulfillment** is confirmed. A single **Order** can produce multiple **Invoices** if items ship in separate **Shipments**."
> **Dev:** "So if a **Shipment** is cancelled before dispatch, no **Invoice** exists for it?"
> **Domain expert:** "Exactly. The **Invoice** lifecycle is tied to the **Fulfillment**, not the **Order**."

## Flagged ambiguities

- "account" was used to mean both **Customer** and **User** — these are distinct concepts: a **Customer** places orders, while a **User** is an authentication identity that may or may not represent a **Customer**.
老师讲解 · 对应上方原文 · 含教学举例

定义之外,关系和对话能暴露隐含误解

表格回答某概念是什么,关系回答它与别的概念怎样相连。比如一门课程包含多个课时,一个学习者可以收藏多门课程。基数说明一个还是多个,常会影响保存结构和界面。

示例对话能检验词是否自然工作:“读完课时就算掌握吗?”“不,掌握还需要在新情境作出正确判断。”这样比只写“掌握:已掌握”更有用。

原文订单、发票的定义属于示例业务约定,不应当成任何国家税务制度的定义。领域术语的正确性依赖其业务范围。

中文译文

规则

  • 给出明确判断:同一概念多个名字时,选最合适的,列出避免混用的别名。
  • 明确指出冲突,在歧义部分写出建议。
  • 只收录业务专家关心的概念。模块或类名除非有业务含义,否则跳过。
  • 每项定义最多一句,说明是什么,不用一串动作代替定义。
  • 用加粗术语表达关系,明确时说明一对一、一对多等数量关系。
  • 不收录数组、函数、端点等通用编程词,除非在此业务有特殊意义。
  • 自然形成子领域、生命周期或参与者分组时,分别建表;单一领域可用一张,不强分。
  • 写 3—5 次简短的开发者与专家交流,展示准确用词、概念关系和彼此界限。

<example>

English · 英文原文

Rules

  • Be opinionated. When multiple words exist for the same concept, pick the best one and list the others as aliases to avoid.
  • Flag conflicts explicitly. If a term is used ambiguously in the conversation, call it out in the "Flagged ambiguities" section with a clear recommendation.
  • Only include terms relevant for domain experts. Skip the names of modules or classes unless they have meaning in the domain language.
  • Keep definitions tight. One sentence max. Define what it IS, not what it does.
  • Show relationships. Use bold term names and express cardinality where obvious.
  • Only include domain terms. Skip generic programming concepts (array, function, endpoint) unless they have domain-specific meaning.
  • Group terms into multiple tables when natural clusters emerge (e.g. by subdomain, lifecycle, or actor). Each group gets its own heading and table. If all terms belong to a single cohesive domain, one table is fine — don't force groupings.
  • Write an example dialogue. A short conversation (3-5 exchanges) between a dev and a domain expert that demonstrates how the terms interact naturally. The dialogue should clarify boundaries between related concepts and show terms being used precisely.

<example>

中文译文

示例对话

开发者:没有 Docker,怎样测试同步服务?

专家:传文件系统层代替 Docker 层。它实现相同 Sandbox service 接口,用本地目录作为沙箱。

开发者:sync-in 仍会创建 bundle 并解包吗?

专家:会。同步服务不必知道后面是哪一层,只调用 execcopyIn。文件系统层将它们作为本地 shell 命令执行。

</example>

English · 英文原文

Example dialogue

Dev: "How do I test the sync service without Docker?"

Domain expert: "Provide the filesystem layer instead of the Docker layer. It implements the same Sandbox service interface but uses a local directory as the sandbox."

Dev: "So sync-in still creates a bundle and unpacks it?"

Domain expert: "Exactly. The sync service doesn't know which layer it's talking to. It calls exec and copyIn — the filesystem layer just runs those as local shell commands."

</example>

中文译文

再次运行

读现有词汇表,加入新讨论的词;理解变化时更新定义;标出新歧义;改写示例对话,纳入新概念。

English · 英文原文

Re-running

When invoked again in the same conversation:

  1. Read the existing UBIQUITOUS_LANGUAGE.md
  2. Incorporate any new terms from subsequent discussion
  3. Update definitions if understanding has evolved
  4. Re-flag any new ambiguities
  5. Rewrite the example dialogue to incorporate new terms
老师讲解 · 对应上方原文 · 含教学举例

随着理解发展更新,但不要无声改变业务含义

再次调用时先读已有词典,纳入新术语、修订理解并重新标歧义。直接重建会丢失此前已确认的边界。

例如从“已读即完成”改为“完成需要测验”,会影响统计和用户预期,不只是文字润色。应明确这是概念变化,并追查依赖它的规格与实现。

与当前 domain-modeling 对照:历史文件主要提取词典,当前方法更主动质疑、用场景检验并记录必要架构决定。两者共享统一语言思想,但职责范围并不完全一样。

原作者:Matt Pocock · 中文翻译为非官方译本

来源:skills/deprecated/ubiquitous-language/SKILL.md ↗

固定版本:62f43a18177be6ec82da242e59ffbc490a4c22ea

先作答,再看参考思路

Q1 · 理解

用自己的话说明:它解决什么问题,完成后会留下什么?

请各用一句话回答。若它只做规划或解释,不要把“已开发”“已部署”写成产物。

Q2 · 判断

只有中英词语对照,没有定义和关系,是合格的领域词典吗?

我已思考,查看参考思路

通常不够。它无法解决同名概念的边界,也不能帮助业务和代码使用相同语义。

Q3 · 追问

原文中哪条要求在你的环境下可能不成立?

说出具体一句及其前提,例如工具不可用、资料缺失、已有项目约定冲突,或它只是作者偏好。把你的答案带回课堂,我们据此继续讨论。

课堂回传格式:第 48 课 / 我的理解 / Q2 回答 / 仍不理解的原句。这里是阅读教材;实时问答在我们的对话中进行。

把方法放进一个具体情境

教学案例:“文章”“讲义”“原文”都可能被叫作内容。若原文只是技能源文件,讲义是老师解释,文章是公开表达,三者必须区分,才能正确保存和发布。

边界与容易误读的地方

不要把通用函数名和实现术语都放进领域词典。旧文件名与新文件名同时存在时,需要明确权威来源。

讨论后再实践:先判断上述情境是否适用,再选择真实任务。现在无需安装、运行命令或修改现有项目。

关联阅读