refactor-extract-and-isolate

majiayu000 的头像作者 majiayu000

提取方法、类或模块以降低复杂度和提高隔离性。当函数过长、类承担过多责任或关注点混合时使用。

📖 中文导读:提取方法、类或模块以降低复杂度和提高隔离性。当函数过长、类承担过多责任或关注点混合时使用。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: refactor-extract-and-isolate description: "[Code Quality] Extracts methods, classes, or modules to reduce complexity and improve isolation. Use when functions are too long, classes have too many responsibilities, or concerns are mixed."

Refactor: Extract and Isolate

Break down complex code into focused, reusable units.

Extract Method

When to Extract

  • Function > 20 lines
  • Code block has a distinct purpose
  • Same logic repeated
  • Deep nesting (> 3 levels)

Extract Class

When to Extract

  • Class > 300 lines
  • Multiple distinct responsibilities
  • Group of related methods/properties
  • Feature envy

Extract Protocol/Interface

When to Extract

  • Multiple implementations possible
  • Testing requires mocking
  • Dependency inversion needed

Checklist

  1. Identify extraction boundary
  2. Choose good name for new unit
  3. Move code to new location
  4. Update references
  5. Add tests for new unit
  6. Verify original tests pass