跳到正文
Skillpedia
API 与服务器(后端)48k · #4348

ddd-tactical-patterns

它能做什么

这个工具会按照一种叫做“DDD 战术模式”的设计原则来组织你的程序代码。它关注如何构建程序的核心部分,使其更易理解和维护,尤其是在业务规则比较复杂的时候。

适用场景

  • ✓当你需要把业务规则转化为代码时。
  • ✓当你要决定如何组织程序的不同部分时。
  • ✓当你需要改进混乱或逻辑不清晰的代码时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/ddd-tactical-patterns/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/ddd-tactical-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“把这些业务规则翻译成代码:[在这里填写规则]”

每周 5 个新技能,1 分钟读完。

工作原理

工具会把你的代码组织成“实体”和“值对象”等模块,并确保重要的规则(不变量)始终得到遵守。它还会帮你定义这些模块之间如何通信,以及如何记录重要的变化。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

DDD Tactical Patterns

Use this skill when

  • Translating domain rules into code structures.
  • Designing aggregate boundaries and invariants.
  • Refactoring an anemic model into behavior-rich domain objects.
  • Defining repository contracts and domain event boundaries.

Do not use this skill when

  • You are still defining strategic boundaries.
  • The task is only API documentation or UI layout.
  • Full DDD complexity is not justified.

Instructions

  1. Identify invariants first and design aggregates around them.
  2. Model immutable value objects for validated concepts.
  3. Keep domain behavior in domain objects, not controllers.
  4. Emit domain events for meaningful state transitions.
  5. Keep repositories at aggregate root boundaries.

If detailed checklists are needed, open references/tactical-checklist.md.

Example

class Order {
  private status: "draft" | "submitted" = "draft";

  submit(itemsCount: number): void {
    if (itemsCount === 0) throw new Error("Order cannot be submitted empty");
    if (this.status !== "draft") throw new Error("Order already submitted");
    this.status = "submitted";
  }
}

Limitations

  • This skill does not define deployment architecture.
  • It does not choose databases or transport protocols.
  • It should be paired with testing patterns for invariant coverage.
常见问题

什么是“不变量”?

不变量是程序中某部分必须始终成立的业务规则。例如,一个银行账户的余额永远不能为负数。

什么是“实体”和“值对象”?

实体是有自己身份标识、会随时间变化的事物(比如“用户”)。值对象是由其属性定义、没有自己身份标识的事物(比如“地址”)。

什么是“聚合”?

聚合是一组协同工作、被视为一个整体的实体和值对象。它们有助于维护业务规则的一致性。

详情

作者的原始描述

Apply DDD tactical patterns in code using entities, value objects, aggregates, repositories, and domain events with explicit invariants.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4348
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能