Back to skills
extension
Category: Development & EngineeringNo API key required

principle-solid

Apply the five principles of object-oriented design (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) to systematically evaluate the quality of class and module designs. Use when reviewing architectural designs, refactoring existing code, or examining class responsibility assignments. Supports multi-level checklists and diagnosis with fixes for principle violations.

personAuthor: jakexiaohubgithub

SOLID Principles Skill

Scope: COMMON(全阶段通用)

版本: 0.1.0(占位)| 创建日期: 2025-11-27


概述

SOLID 是面向对象设计的五大基本原则:

┌─────────────────────────────────────────────────────┐
│              🏛️ SOLID Principles                    │
├──────────┬──────────────────────────────────────────┤
│    S     │ Single Responsibility Principle         │
│    O     │ Open-Closed Principle                   │
│    L     │ Liskov Substitution Principle           │
│    I     │ Interface Segregation Principle         │
│    D     │ Dependency Inversion Principle          │
└──────────┴──────────────────────────────────────────┘

五大原则

S - 单一职责原则 (SRP)

  • [ ] 每个类/模块只有一个改变的理由
  • [ ] 职责清晰,不混杂无关功能
  • [ ] 高内聚,低耦合

O - 开闭原则 (OCP)

  • [ ] 对扩展开放,对修改关闭
  • [ ] 通过抽象实现扩展
  • [ ] 新增功能不需修改现有代码

L - 里氏替换原则 (LSP)

  • [ ] 子类可以替换父类而不影响程序正确性
  • [ ] 子类不削弱父类的前置条件
  • [ ] 子类不加强父类的后置条件

I - 接口隔离原则 (ISP)

  • [ ] 接口小而专注
  • [ ] 客户端不依赖它不需要的接口
  • [ ] 多个专用接口优于一个通用接口

D - 依赖反转原则 (DIP)

  • [ ] 高层模块不依赖低层模块,都依赖抽象
  • [ ] 抽象不依赖细节,细节依赖抽象
  • [ ] 依赖注入

分级检查策略

L1-STREAMLINED

  • 每原则检查 1 个核心点(共 5 项)
  • 关注明显违反
  • 通过标准:5 项中 4 项通过(≥80%)

L2-BALANCED

  • 每原则检查 2-3 个关键点(共 10-15 项)
  • 结合代码示例分析
  • 通过标准:10 项中 8 项通过(≥80%)

L3-RIGOROUS

  • 全面检查所有子项(15+ 项)
  • 依赖图分析 + 耦合度量化
  • 记录违反点及重构建议
  • 通过标准:15 项中 14 项通过(≥93%)

>> 命令

>>solid_check_l1     # SOLID 快速检查(5项各1个关键点)
>>solid_check_l2     # SOLID 标准检查(含代码示例分析)
>>solid_violation    # 识别 SOLID 违反点

相关 Skills

  • 同类: principle-dry, principle-kiss, principle-yagni, principle-soc(设计原则家族)
  • 应用: vertical-slice, component-boundary, layer-design(设计阶段使用)
  • 验证: code-review, refactoring(代码阶段验证 SOLID 符合度)

TODO: 待细化各原则的具体检查规则和代码示例