| name | refactoring-patterns |
| description | Systematic code refactoring guide with design patterns. Use when refactoring spaghetti code, applying Strategy pattern to conditional branches, extracting functions by SRP, or replacing magic numbers with named constants. |
Refactoring Patterns
๋ฆฌํฉํ ๋ง ์ํฌํ๋ก์ฐ
1. ๋ถ์
- ์๋ณธ ์ฝ๋์ ์
์ถ๋ ฅ ๋์์ ์์ ํ ์ดํด
- ๋งค์ง ๋๋ฒ, ์ค๋ณต ์ฝ๋, ๊ธด ์กฐ๊ฑด ๋ถ๊ธฐ ์๋ณ
- ๊ฐ ์ฝ๋ ๋ธ๋ก์ ์ฑ
์ ํ์
2. ์ค๊ณ
- ๋งค์ง ๋๋ฒ -> ๋ช
๋ช
๋ ์์ (constants.js)
- ์กฐ๊ฑด ๋ถ๊ธฐ(if/else, switch) -> ์ ๋ต ํจํด (pricingStrategies.js)
- ํ๋์ ํฐ ํจ์ -> SRP ๊ธฐ๋ฐ ๋จ์ผ ์ฑ
์ ํจ์ ๋ถ๋ฆฌ
- ํฉํ ๋ฆฌ ํจ์๋ก ์ ๋ต ๊ฐ์ฒด ์์ฑ
3. ๊ตฌํ
- ์์ ์ ์ ํ์ผ ๋ถ๋ฆฌ
- ์ ๋ต ํด๋์ค ๊ตฌํ (base + ๊ตฌ์ฒด ์ ๋ต)
- ์ค์ผ์คํธ๋ ์ดํฐ ํจ์์์ ์ ๋ต ํธ์ถ
- SRP ํจ์ ๋ถ๋ฆฌ:
- calculateLineItem() - ๋จ์ผ ํญ๋ชฉ ๊ณ์ฐ
- applyDiscount() - ํ ์ธ ์ ์ฉ
- calculateTax() - ์ธ๊ธ ๊ณ์ฐ
- applyBulkDiscount() - ๋๋ ํ ์ธ
- updateHistory() - ์ด๋ ฅ ๊ฐฑ์
- calculateOrder() - ์ค์ผ์คํธ๋ ์ดํฐ
4. ํ
์คํธ
- ์๋ณธ vs ๋ฆฌํฉํ ๋ง ๋์ผ์ฑ ํ
์คํธ (๋์ผ ์
๋ ฅ -> ๋์ผ ์ถ๋ ฅ)
- ๊ฐ ์ ๋ต๋ณ ๋จ์ ํ
์คํธ
- ๊ฒฝ๊ณ๊ฐ ํ
์คํธ (์๋ 50, 51, 100, 101)
- ์ฃ์ง ์ผ์ด์ค (๋น ๋ฐฐ์ด, ํ ์ธ 0%, ์ธ๊ธ 0%)
์์ธ ์ฝ๋ ํจํด์ references/patterns.md ์ฐธ์กฐ.