Files
2nd/10_Wiki/Topic_Programming/Architecture/Sprout & Wrap Techniques (스프라우트 & 랩 기법).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

6.1 KiB
Raw Blame History

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-sprout-wrap-techniques-스프라우트-랩-기 Sprout & Wrap Techniques (스프라우트 & 랩 기법) 10_Wiki/Topics verified self
Sprout and Wrap
Wrap Method
Wrap Class
스프라우트 랩
none A 0.9 applied
refactoring
legacy-code
michael-feathers
2026-05-10 pending
language framework
java junit

Sprout & Wrap Techniques (스프라우트 & 랩 기법)

매 한 줄

"매 legacy code 의 직접 수정 X — 매 sprout 의 옆에 새 method/class 의 추가, 매 wrap 의 기존 caller 의 둘러쌈". Michael Feathers, Working Effectively with Legacy Code (2004) 의 4 paired 기법: Sprout Method, Sprout Class, Wrap Method, Wrap Class.

매 핵심

매 4 techniques

  • Sprout Method: 매 새 method 의 옆에 grow, 매 caller 의 1줄 add.
  • Sprout Class: 매 새 class 의 grow, 매 caller 의 instantiate + delegate.
  • Wrap Method: 매 기존 method rename → 매 same name 의 new method 의 둘러쌈 (before/after logic).
  • Wrap Class: 매 decorator/proxy 의 wrap (cross-cutting: logging, auth).

매 Sprout vs Wrap

  • Sprout: 매 add new logic to existing operation.
  • Wrap: 매 add cross-cutting (before/after) to existing operation 의 callers.

매 응용

  1. Add validation before legacy save.
  2. Add audit logging across all calls.
  3. Add caching layer transparently.
  4. Add feature flag toggle.

💻 패턴

Sprout Method

public void process(Order o) {
    // legacy untouched
    repo.save(o);
    notifyCustomer(o); // sprouted
}

void notifyCustomer(Order o) { // tested
    email.send(o.customer(), template(o));
}

Sprout Class — when sprout method 의 not enough

// Original legacy class — touch minimally
public class OrderProcessor {
    public void process(Order o) {
        repo.save(o);
        new OrderNotifier(email, sms).notifyAll(o); // sprouted class
    }
}

// New, fully tested
public class OrderNotifier {
    private final EmailService email;
    private final SmsService sms;
    public OrderNotifier(EmailService e, SmsService s) { this.email = e; this.sms = s; }
    public void notifyAll(Order o) {
        email.send(o.customer().email(), "thanks");
        if (o.customer().smsOptIn()) sms.send(o.customer().phone(), "order placed");
    }
}

Wrap Method — rename + intercept

public class Pay {
    // Step 1: rename original to *Internal
    private void payInternal(Order o) {
        gateway.charge(o.amount());
    }

    // Step 2: new method with same original name
    public void pay(Order o) {
        audit.log("pay.start", o.id());      // before
        payInternal(o);                       // delegate
        audit.log("pay.end", o.id());        // after
    }
}

Wrap Class — Decorator

public interface PaymentGateway { void charge(long amount); }

public class StripeGateway implements PaymentGateway { /* legacy untouched */ }

public class LoggingGateway implements PaymentGateway {
    private final PaymentGateway inner;
    private final Logger log;
    public LoggingGateway(PaymentGateway inner, Logger log) {
        this.inner = inner; this.log = log;
    }
    @Override public void charge(long amount) {
        log.info("charge.start amount={}", amount);
        try { inner.charge(amount); }
        finally { log.info("charge.end"); }
    }
}

// Wire-up: clients see PaymentGateway, get wrapped version
PaymentGateway gw = new LoggingGateway(new StripeGateway(), log);

Wrap Class for caching

public class CachingRepo implements OrderRepository {
    private final OrderRepository inner;
    private final Map<Long, Order> cache = new ConcurrentHashMap<>();
    public CachingRepo(OrderRepository inner) { this.inner = inner; }
    public Order findById(long id) {
        return cache.computeIfAbsent(id, inner::findById);
    }
    public Order save(Order o) {
        var saved = inner.save(o);
        cache.put(saved.id(), saved);
        return saved;
    }
}

Python — wrap with closure

def wrap_with_audit(fn, audit):
    def wrapped(*a, **kw):
        audit.log(f"{fn.__name__}.start")
        try: return fn(*a, **kw)
        finally: audit.log(f"{fn.__name__}.end")
    return wrapped

pay = wrap_with_audit(legacy_pay, audit)

Sprout 의 test (TDD first)

@Test
void notifyCustomer_priorityOrder_sendsPriorityTemplate() {
    var o = new Order(customer, true);
    new OrderProcessor(repo, emailMock, smsMock).notifyCustomer(o);
    verify(emailMock).send(customer.email(), "priority-thanks");
}

매 결정 기준

상황 Approach
Add small new logic to legacy method Sprout Method
New logic 의 large/independent Sprout Class
Add before/after to specific method Wrap Method
Cross-cutting (logging, cache, auth) across many callers Wrap Class (decorator)
Legacy call sites 의 모두 update 의 가능 Direct refactor 의 OK

기본값: 매 legacy add → Sprout. 매 cross-cutting → Wrap Class.

🔗 Graph

🤖 LLM 활용

언제: 매 untested legacy code 의 modification 필요; 매 cross-cutting concern 의 add. 언제 X: 매 codebase 의 well-tested — 매 직접 refactor 의 cleaner.

안티패턴

  • Wrap without rename: 매 infinite recursion.
  • Sprout class 의 1-method-only forever: 매 결국 dead weight — 매 collapse 의 검토.
  • Wrap class 의 not used by all callers: 매 inconsistent behavior — DI 의 enforce.
  • No tests on sprouted/wrapped code: 매 entire technique 의 point 의 lost.

🧪 검증 / 중복

  • Verified (Feathers, WELC ch.67, 2004; Fowler refactoring catalog).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — full Sprout & Wrap quartet with Java/Python patterns