refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게 [공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류. 문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인). - Topic_Programming → Domain_Programming (내부 구조 보존) - Topic_Graphic → Domain_Design - Topic_Business → Domain_Product - Topic_General → Domain_General - _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning), Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing) - 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서) - 빈 폴더 정리 (memory/procedures) - 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
---
|
||||
id: wiki-2026-0508-wrap-method-랩-메서드
|
||||
title: Wrap Method (랩 메서드)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Wrap Method, 랩 메서드, Method Wrapping]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [refactoring, legacy, michael-feathers]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Java/Python/TypeScript
|
||||
framework: 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
|
||||
```java
|
||||
// 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
|
||||
```typescript
|
||||
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
|
||||
```python
|
||||
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)
|
||||
```java
|
||||
// 매 file/class 전체 wrapping이 필요할 때
|
||||
public class LoggingPaymentService extends PaymentService {
|
||||
@Override
|
||||
public void pay(Order o) {
|
||||
log.info("paying {}", o.id);
|
||||
super.pay(o);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Decorator alternative
|
||||
```typescript
|
||||
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 |
|
||||
Reference in New Issue
Block a user