Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →建议设计模式并评估 SOLID 原则。「建议设计模式」「可以用什么模式?」「检查 SOLID 原则」「检测反模式」等触发。
.claude/skills/wasabeef-solid-9b42a3/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 16% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 34% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 2% | 0% |
| case-09 | ✓→✓ | = Same ✓ | 227% | 0% |
| case-10 | ✓→✓ | = Same ✓ | 261% | 0% |
提出可应用于代码库的设计模式,评估 SOLID 原则的遵守情况。
bash/design-patterns [分析对象] [选项]
--suggest : 提出可应用的模式 (默认)--analyze : 分析现有模式的使用情况--refactor : 生成重构方案--solid : 检查 SOLID 原则的遵守情况--anti-patterns : 检测反模式bash# 整个项目的模式分析 /design-patterns # 对特定文件提出模式建议 /design-patterns src/services/user.js --suggest # SOLID 原则检查 /design-patterns --solid # 反模式检测 /design-patterns --anti-patterns
textS - Single Responsibility Principle (单一职责原则) O - Open/Closed Principle (开闭原则) L - Liskov Substitution Principle (里氏替换原则) I - Interface Segregation Principle (接口隔离原则) D - Dependency Inversion Principle (依赖倒置原则)
text设计模式分析报告 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 当前使用的模式 ├─ Observer Pattern: EventEmitter (12 处) ├─ Factory Pattern: UserFactory (3 处) ├─ Singleton Pattern: DatabaseConnection (1 处) └─ Strategy Pattern: PaymentProcessor (5 处) 推荐模式 ├─ [HIGH] Repository Pattern │ └─ 对象: src/models/*.js │ └─ 原因: 分离数据访问逻辑 │ └─ 示例: │ class UserRepository { │ async findById(id) { ... } │ async save(user) { ... } │ } │ ├─ [MED] Command Pattern │ └─ 对象: src/api/handlers/*.js │ └─ 原因: 统一请求处理 │ └─ [LOW] Decorator Pattern └─ 对象: src/middleware/*.js └─ 原因: 改进功能组合 SOLID 原则违反 ├─ [S] UserService: 同时负责认证和权限管理 ├─ [O] PaymentGateway: 添加新支付方式需要修改 ├─ [D] EmailService: 直接依赖具体类 └─ [I] IDataStore: 包含未使用的方法 重构建议 1. 将 UserService 拆分为认证和权限管理 2. 引入 PaymentStrategy 接口 3. 定义 EmailService 接口 4. 按用途拆分 IDataStore
bash# 模式应用的影响分析 /design-patterns --impact-analysis Repository # 生成特定模式的实现示例 /design-patterns --generate Factory --for src/models/Product.js # 模式组合建议 /design-patterns --combine --context "带缓存的 API" # 架构模式评估 /design-patterns --architecture MVC
javascriptclass OrderService { processOrder(order, paymentType) { if (paymentType === "credit") { // 信用卡处理 } else if (paymentType === "paypal") { // PayPal 处理 } // 其他支付方式... } }
javascript// 策略接口 class PaymentStrategy { process(amount) { throw new Error("必须实现 process 方法"); } } // 具体策略 class CreditCardPayment extends PaymentStrategy { process(amount) { /* 实现 */ } } // 上下文 class OrderService { constructor(paymentStrategy) { this.paymentStrategy = paymentStrategy; } processOrder(order) { this.paymentStrategy.process(order.total); } }
Other measured skills in the registry, with their headline benchmark lift.