Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →建議設計模式並評估 SOLID 原則。「建議設計模式」「可以用什麼模式?」「檢查 SOLID 原則」「偵測反模式」等觸發。
.claude/skills/wasabeef-solid-b7b6df/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-05 | ✗→✓ | ▲ Improved | -1% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 29% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 10% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 61% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 12% | 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.