技能 编程开发 领域驱动设计战术模式

领域驱动设计战术模式

v20260509
ddd-tactical-patterns
本技能指导如何应用领域驱动设计(DDD)的战术模式,涉及聚合根、值对象、仓库和领域事件等。它帮助开发者将复杂的业务领域规则转化为结构清晰、行为丰富的代码,确保业务不变量得到明确维护。
获取技能
305 次下载
概览

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.
信息
Category 编程开发
Name ddd-tactical-patterns
版本 v20260509
大小 1.51KB
更新时间 2026-05-10
语言