Files
2nd/10_Wiki/Topic_Programming/Architecture/Wrap Method (랩 메서드).md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

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
Wrap Method
랩 메서드
Method Wrapping
none A 0.9 applied
refactoring
legacy
michael-feathers
2026-05-10 pending
language framework
Java/Python/TypeScript refactoring

Wrap Method (랩 메서드)

매 한 줄

"매 새 behavior를 기존 method 호출 사이에 끼우려면 매 기존 method를 rename하고 매 같은 이름의 wrapper를 매 새로 만든다". Michael Feathers의 Working Effectively with Legacy Code (2004) 의 seam 기법으로, 매 test가 어려운 legacy code에 매 새 cross-cutting behavior 추가.

매 핵심

매 절차

  1. 매 기존 pay()payAndRecordTransaction() 으로 rename (또는 private 화).
  2. 매 동일 signature의 pay() wrapper 신규.
  3. 매 wrapper에 새 step + delegate.
  4. 매 caller는 변경 X.

매 vs Decorator

  • Wrap Method: 매 same class, 매 같은 method 의 in-place 확장.
  • Decorator: 매 different class, 매 wrapping object 의 외부 확장.

매 응용

  1. Legacy code에 logging/audit 추가.
  2. Feature flag wrapping.
  3. 매 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

🤖 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