/cook-zh-tw:design-patterns runs instead · from cook-zh-tw
Suggests design patterns (creational, structural, behavioral) and evaluates SOLID principle adherence in a codebase. Detects anti-patterns and generates refactoring plans.
This skill never runs in Claude Code
It ships in cook-zh-tw at skills/, but /cook-zh-tw: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
2 plugins ship this exact skill · first indexed Jul 16, 2026
39 skills in this plugin
npx claudepluginhub wasabeef/claude-code-cookbook --plugin cook-zh-twOther plugins' skills for the same job