Replace Conditional with Polymorphism (조건식을 다형성으로 바꾸기)
10_Wiki/Topics
verified
self
Replace Conditional with Polymorphism
RCwP
Polymorphism Refactoring
none
A
0.9
applied
refactoring
oop
design-pattern
fowler
2026-05-10
pending
language
framework
TypeScript
none
Replace Conditional with Polymorphism (조건식을 다형성으로 바꾸기)
매 한 줄
"매 type-discriminating switch/if-chain 을 매 polymorphic dispatch 로 교체". Fowler Refactoring 2e (2018) Ch.10. 매 type code 가 add 시마다 매 switch 들 모두 수정 필요한 shotgun surgery 의 표준 처방. 매 modern alternative — discriminated union + exhaustiveness, strategy map, pattern matching — 도 같은 본질을 공유한다.
매 핵심
매 trigger smell
매 동일 switch (kind) 가 codebase 여러 곳에 반복.
매 새 type 추가가 매 N 곳의 switch 수정 강제.
매 default branch 가 silently incorrect.
매 mechanics (Fowler)
매 self-encapsulating type 추출 (subclass 또는 strategy).