スキル一覧に戻る
PaulRBerg

dry-refactor

by PaulRBerg

dry-refactorは、other分野における実用的なスキルです。複雑な課題への対応力を強化し、業務効率と成果の質を改善します。

69🍴 11📅 2026年1月22日
GitHubで見るManusで実行

SKILL.md


name: dry-refactor agent: Plan context: fork user-invocable: false description: This skill should be used when the user asks to "refactor duplicate code", "apply DRY principles", "eliminate code repetition", "extract common functionality", or mentions code duplication, similar patterns, repeated logic, or reusable abstractions.

DRY Refactoring

Process

  1. Identify - Exact copies, similar patterns, parallel hierarchies, naming patterns (data1/data2, handleXClick)
  2. Analyze - Coupling, cohesion, frequency (Rule of Three: wait for 3+ occurrences), volatility
  3. Refactor - Choose technique below, extract incrementally, test after each step

Techniques

Extract Function - Same logic in multiple places

getFullName(user: User) => `${user.firstName} ${user.lastName}`

Extract Variable - Repeated expression

const isWorkingAge = user.age >= 18 && user.age < 65;

Parameterize - Code differs only in values

validateField(value: string, pattern: RegExp)
// Use: validateField(email, EMAIL_REGEX)

Extract Class - Related functions scattered

class UserRewards {
  calculateDiscount(user, amount) { }
  getLoyaltyPoints(user) { }
}

Polymorphism - Repeated switch/if-else

interface PaymentProcessor { process(amount: number): void }
class CreditProcessor implements PaymentProcessor { }

Strategy Pattern - Duplicated algorithm selection

const strategies = { date: byDate, name: byName };
items.sort(strategies[sortType] ?? byPriority);

Pull Up Method - Identical methods in subclasses

class BaseUser { getDisplayName() { } }
class AdminUser extends BaseUser { }

Detection

Code Smells: Look for numbered variables (data1, data2), parallel function names (handleXClick), near-identical code differing only in constants, repeated validation/error handling, parallel class structures, large switches in multiple places, repeated null checks, magic numbers

Rule of Three: Wait for 3+ occurrences before abstracting

When NOT to DRY

  • Coincidental similarity - Avoid abstracting different domains/business rules that happen to look alike (will diverge)
  • Premature abstraction - Wait until pattern is clear; early abstraction often guesses wrong
  • Single use - Skip abstraction when code appears 1-2 times and is unlikely to grow
  • Test clarity - Prefer readable test setup over DRY
  • Over-engineering - Avoid abstracting every 2-3 line similarity

Patterns

  • Configuration over code - Use data structures to eliminate conditionals
  • Template Method - Define skeleton in base, vary steps in subclasses
  • Dependency Injection - Parameterize dependencies to reduce coupling
  • Builder - Construct complex objects incrementally

Best Practices

  • Refactor only after tests pass (green)
  • Apply one refactoring at a time
  • Commit changes frequently
  • Name abstractions for intent, not implementation
  • Consider performance impact of abstractions
  • Review abstractions with team before finalizing

スコア

総合スコア

70/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

+5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

レビュー

💬

レビュー機能は近日公開予定です