f8b21af4be
10_Wiki/Topics 대규모 정리: - 오류 캡처/미완성 stub 문서 227개 제거 - 교차폴더 중복 43클러스터 병합 (63파일 → redirect) - 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건 - 카테고리 MOC 6개 신규 생성 - Graph 섹션 미해결 related-keyword 링크 10,058건 제거 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4.0 KiB
4.0 KiB
id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
| id | title | category | status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | verification_status | tags | raw_sources | last_reinforced | github_commit | tech_stack | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wiki-2026-0508-wrap-method-랩-메서드 | Wrap Method (랩 메서드) | 10_Wiki/Topics | verified | self |
|
none | A | 0.9 | applied |
|
2026-05-10 | pending |
|
Wrap Method (랩 메서드)
매 한 줄
"매 새 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 의 외부 확장.
매 응용
- Legacy code에 logging/audit 추가.
- Feature flag wrapping.
- 매 deprecation soft-warn.
💻 패턴
Java — Add audit
// before
public class PaymentService {
public void pay(Order o) { /* charge logic */ }
}
// after
public class PaymentService {
public void pay(Order o) {
audit.log("pay.start", o.id);
payInternal(o);
audit.log("pay.end", o.id);
}
private void payInternal(Order o) { /* charge logic */ }
}
TypeScript — Feature flag
class Checkout {
async submit(cart: Cart): Promise<Receipt> {
if (!flags.newCheckout) return this.submitLegacy(cart);
// new implementation
return this.submitV2(cart);
}
private async submitLegacy(cart: Cart): Promise<Receipt> { /* old */ }
private async submitV2(cart: Cart): Promise<Receipt> { /* new */ }
}
Python — Deprecation wrap
import warnings
class Api:
def fetch(self, id):
warnings.warn("fetch() will be removed in v3, use get()", DeprecationWarning)
return self._fetch_impl(id)
def _fetch_impl(self, id):
# original logic
...
Wrap Class (variant)
// 매 file/class 전체 wrapping이 필요할 때
public class LoggingPaymentService extends PaymentService {
@Override
public void pay(Order o) {
log.info("paying {}", o.id);
super.pay(o);
}
}
Decorator alternative
function audited<T extends (...a: any[]) => any>(fn: T, name: string): T {
return ((...args: any[]) => {
audit.log(`${name}.start`);
const r = fn(...args);
audit.log(`${name}.end`);
return r;
}) as T;
}
const pay = audited(originalPay, 'pay');
매 결정 기준
| 상황 | Approach |
|---|---|
| 매 same method에 매 minor 추가 step | Wrap Method |
| 매 multiple methods 의 cross-cut | AOP / Decorator pattern |
| 매 entire class 의 wrapping | Wrap Class / Subclass and Override |
| 매 new code, 매 legacy 아님 | Composition / DI |
기본값: 매 legacy seam 필요 → Wrap Method, 매 그 외 → composition.
🔗 Graph
- 부모: Refactoring_Best_Practices
- 변형: Wrap-Class
- 응용: AOP_Aspect-Oriented_Programming
- Adjacent: Seam · Feature-Flag
🤖 LLM 활용
언제: 매 legacy method에 매 새 behavior, 매 caller 변경 X. 언제 X: 매 fundamental redesign 이 필요할 때 — Strategy/Composition.
❌ 안티패턴
- 매 무한 wrapping: 매 5겹 wrap → unreadable.
- 매 wrapper에 logic 누적: wrapper의 single 책임 (cross-cut) 만 유지.
🧪 검증 / 중복
- Verified (Feathers, Working Effectively with Legacy Code, 2004).
- 신뢰도 A.
🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — Wrap Method seam pattern + 다국어 examples |