/cook-zh-cn:design-patterns runs instead · from cook-zh-cn
Suggests design patterns (creational, structural, behavioral) and evaluates SOLID principle compliance in codebases. Detects anti-patterns and generates refactoring plans.
This skill never runs in Claude Code
It ships in cook-zh-cn at skills/, but /cook-zh-cn:design-patterns (a command, or a skill Claude Code finds first) has the same name: typing it, or Claude choosing it, runs that one instead.
提出可应用于代码库的设计模式,评估 SOLID 原则的遵守情况。
/design-patterns [分析对象] [选项]
--suggest : 提出可应用的模式 (默认)--analyze : 分析现有模式的使用情况--refactor : 生成重构方案--solid : 检查 SOLID 原则的遵守情况--anti-patterns : 检测反模式# 整个项目的模式分析
/design-patterns
# 对特定文件提出模式建议
/design-patterns src/services/user.js --suggest
# SOLID 原则检查
/design-patterns --solid
# 反模式检测
/design-patterns --anti-patterns
S - Single Responsibility Principle (单一职责原则)
O - Open/Closed Principle (开闭原则)
L - Liskov Substitution Principle (里氏替换原则)
I - Interface Segregation Principle (接口隔离原则)
D - Dependency Inversion Principle (依赖倒置原则)
设计模式分析报告
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
当前使用的模式
├─ 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
# 模式应用的影响分析
/design-patterns --impact-analysis Repository
# 生成特定模式的实现示例
/design-patterns --generate Factory --for src/models/Product.js
# 模式组合建议
/design-patterns --combine --context "带缓存的 API"
# 架构模式评估
/design-patterns --architecture MVC
class OrderService {
processOrder(order, paymentType) {
if (paymentType === "credit") {
// 信用卡处理
} else if (paymentType === "paypal") {
// PayPal 处理
}
// 其他支付方式...
}
}
// 策略接口
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);
}
}
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wasabeef/claude-code-cookbook --plugin cook-zh-cn39 skills in this plugin
2 plugins ship this exact skill · first indexed Jul 16, 2026
Other plugins' skills for the same job