single-responsibility

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

单一职责原则

Single Responsibility Principle

每个文件、函数、模块应该只负责一个明确的功能或职责。

Each file, function, and module should only be responsible for one clear function or responsibility.

⚠️ 核心强制要求

⚠️ Core Mandatory Requirements

1. 文件级别

1. File Level

  • 文件的主要功能可以用一句话描述
  • 所有函数/类都与主要功能相关
  • The main function of the file can be described in one sentence
  • All functions/classes are related to the main function

2. 函数级别

2. Function Level

  • 函数名清晰表达单一职责
  • 内部逻辑围绕一个明确目标
  • The function name clearly expresses the single responsibility
  • Internal logic revolves around a clear goal

3. 模块级别

3. Module Level

  • 按业务领域或技术层次划分
  • 不存在循环依赖

  • Divided by business domain or technical level
  • No circular dependencies

AI Agent 行为要求

AI Agent Behavior Requirements

创建代码时

When Creating Code

  1. 在编码前规划好职责边界
  2. 如果不确定如何划分,主动与用户讨论
  1. Plan responsibility boundaries before coding
  2. If you are not sure how to divide, actively discuss with the user

修改代码时

When Modifying Code

  1. 检查当前职责划分是否合理
  2. 发现问题时提供重构建议
  3. 拆分前与用户确认方案
  1. Check whether the current responsibility division is reasonable
  2. Provide refactoring suggestions when problems are found
  3. Confirm the solution with the user before splitting

发现职责不清时

When Unclear Responsibilities Are Found

提供建议模板:
⚠️ 职责划分建议
当前问题:[描述]
建议拆分方案:[具体文件/职责]
是否执行拆分?
Provide suggestion template:
⚠️ 职责划分建议
当前问题:[描述]
建议拆分方案:[具体文件/职责]
是否执行拆分?

architecture-governance
的组合使用

Combined Use with
architecture-governance

  • 当改动涉及分层边界、依赖方向、接口契约时,先触发
    architecture-governance
  • 当改动核心是职责拆分、边界澄清、文件/类瘦身时,触发本 skill。
  • 若两者同时出现,顺序为:
    1. architecture-governance
      (定架构边界)
    2. single-responsibility
      (做职责拆分)
    3. architecture-governance
      (复核依赖与分层)

  • When the change involves layered boundaries, dependency direction, interface contracts, trigger
    architecture-governance
    first.
  • When the core of the change is responsibility splitting, boundary clarification, file/class slimming, trigger this skill.
  • If both occur at the same time, the order is:
    1. architecture-governance
      (define architecture boundaries)
    2. single-responsibility
      (perform responsibility splitting)
    3. architecture-governance
      (review dependencies and layering)

分类标注

Classification Labeling

  • 本 skill 是可独立复用的通用原则 skill。
  • 在架构治理场景中,作为
    architecture-governance
    的联动子原则使用。

  • This skill is an independently reusable general principle skill.
  • In architecture governance scenarios, it is used as a linked sub-principle of
    architecture-governance
    .

参考资料

References

  • references/file-level.md
    - 文件级别职责划分详细说明
  • references/function-level.md
    - 函数级别职责划分详细说明
  • references/module-level.md
    - 模块级别职责划分详细说明
  • references/file-level.md
    - Detailed description of file-level responsibility division
  • references/function-level.md
    - Detailed description of function-level responsibility division
  • references/module-level.md
    - Detailed description of module-level responsibility division