"매 새 behavior를 기존 method 호출 사이에 끼우려면 매 기존 method를 rename하고 매 같은 이름의 wrapper를 매 새로 만든다". Michael Feathers의 Working Effectively with Legacy Code (2004) 의 seam 기법으로, 매 test가 어려운 legacy code에 매 새 cross-cutting behavior 추가.
매 핵심
매 절차
매 기존 pay() → payAndRecordTransaction() 으로 rename (또는 private 화).
매 동일 signature의 pay() wrapper 신규.
매 wrapper에 새 step + delegate.
매 caller는 변경 X.
매 vs Decorator
Wrap Method: 매 same class, 매 같은 method 의 in-place 확장.
Decorator: 매 different class, 매 wrapping object 의 외부 확장.
classCheckout{asyncsubmit(cart: Cart):Promise<Receipt>{if(!flags.newCheckout)returnthis.submitLegacy(cart);// new implementation
returnthis.submitV2(cart);}privateasyncsubmitLegacy(cart: Cart):Promise<Receipt>{/* old */}privateasyncsubmitV2(cart: Cart):Promise<Receipt>{/* new */}}
Python — Deprecation wrap
importwarningsclassApi:deffetch(self,id):warnings.warn("fetch() will be removed in v3, use get()",DeprecationWarning)returnself._fetch_impl(id)def_fetch_impl(self,id):# original logic...
Wrap Class (variant)
// 매 file/class 전체 wrapping이 필요할 때publicclassLoggingPaymentServiceextendsPaymentService{@Overridepublicvoidpay(Ordero){log.info("paying {}",o.id);super.pay(o);}}