| name | refactoring_patterns |
| description | Common refactoring patterns - Extract, Rename, Move ve code smell çözümleri. |
🔄 Refactoring Patterns
Common refactoring patterns ve code smell çözümleri.
🎯 Altın Kural
Davranışı DEĞİŞTİRME, sadece yapıyı iyileştir
Before: Input X → [Code A] → Output Y
After: Input X → [Code B] → Output Y (AYNI!)
🔍 Code Smells
| Smell | Çözüm |
|---|
| Long Method | Extract Method |
| Large Class | Extract Class |
| Duplicate Code | Extract + Reuse |
| Long Parameter List | Parameter Object |
| Feature Envy | Move Method |
| Data Clumps | Extract Class |
📦 Extract Method
function processOrder(order) {
}
function processOrder(order) {
validateOrder(order);
const total = calculateTotal(order);
return formatOutput(total);
}
🔄 Replace Conditional with Polymorphism
function getPrice(type) {
if (type === 'premium') return 100;
if (type === 'basic') return 50;
return 30;
}
const pricing = { premium: 100, basic: 50, free: 30 };
const getPrice = (type) => pricing[type] ?? 30;
Refactoring Patterns v1.1 - Enhanced
🔄 Workflow
Kaynak: Refactoring.guru & Martin Fowler - Refactoring
Aşama 1: Preparation (Safety First)
Aşama 2: Applying Patterns
Aşama 3: Verification & Cleanup
Kontrol Noktaları
| Aşama | Doğrulama |
|---|
| 1 | Refactoring sırasında yeni özellik eklendi mi? (KESİNLİKLE HAYIR. İki şapka kuralı: Ya Refactor yap ya Feature ekle). |
| 2 | Kodun okunabilirliği arttı mı? (Cognitive Complexity düştü mü?). |
| 3 | Test kapsamı (Coverage) korundu mu? |