[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,99 +2,170 @@
|
||||
id: wiki-2026-0508-seam-접점
|
||||
title: Seam (접점)
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: []
|
||||
aliases: [Seam, Seams, 이음새, 접점, Feathers seam]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
tags: [uncategorized]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [legacy-code, refactoring, testing, feathers]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-08
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: typescript
|
||||
framework: none
|
||||
---
|
||||
|
||||
# [[Seam (접점)]]
|
||||
# Seam (접점)
|
||||
|
||||
## 📌 Brief 소스
|
||||
접점(Seam)은 소스 코드를 직접 수정하지 않고도 프로그램의 동작을 변경하거나 갈아 끼울 수 있는 지점을 의미합니다 [1-3]. 이 개념은 마이클 페더스(Michael Feathers)가 레거시 코드 리팩토링 시 테스트 작성을 방해하는 의존성을 끊어내기 위한 도구로 도입했습니다 [3, 4]. 개발자는 객체(Object), 컴파일 전처리(Preprocessing), 링크(Link) 등의 접점을 활용하여 시스템의 기능을 격리시키고 안전하게 단위 테스트를 작성할 수 있습니다 [5, 6].
|
||||
## 매 한 줄
|
||||
> **"매 코드를 매 수정하지 않고 매 동작을 바꿀 수 있는 지점"**. Michael Feathers (*Working Effectively with Legacy Code*, 2004)의 핵심 개념. Seam은 매 legacy code에 매 test를 매 끼워넣는 매 hinge — 매 dependency를 매 엮어내는 매 join point.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **레거시 코드 딜레마 해결**: 레거시 코드를 안전하게 리팩토링하려면 테스트가 필수적이나, 테스트를 작성하려면 기존 코드를 수정하여 무거운 의존성(DB, 네트워크 등)을 제거해야 하는 모순에 빠집니다 [3, 7]. 접점(Seam)은 원본 코드를 편집하지 않으면서도 외부 의존성 호출 부분을 테스트용 가짜 객체(Mock) 등으로 대체하여 이 딜레마를 해결합니다 [1, 3].
|
||||
* **활성화 지점(Enabling Point)**: 모든 접점은 어떤 동작을 사용할지 결정하고 제어할 수 있는 '활성화 지점'을 갖습니다 [8]. 이 지점을 통해 프로덕션 환경의 동작과 테스트 환경의 동작을 다르게 설정할 수 있습니다 [8].
|
||||
* **접점의 주요 유형**:
|
||||
* **객체 접점 (Object Seams)**: 객체지향 언어에서 가장 널리 쓰이고 유용한 접점입니다 [1, 6]. 어떤 메서드가 실행될지가 호출 시점의 객체 타입이나 전달되는 인자(Argument)에 의해 결정되는 다형성 특징을 이용합니다 [6, 9, 10]. 테스트 시 이 활성화 지점을 통해 테스트용 서브클래스나 가짜 객체를 주입할 수 있습니다 [10].
|
||||
* **전처리 접점 (Preprocessing Seams)**: C나 C++처럼 매크로 전처리기가 컴파일 이전에 실행되는 언어에서 사용 가능한 접점입니다 [5]. `#include`나 `#define` 매크로를 이용해 코드가 컴파일되기 전에 텍스트 자체를 치환하여 실제 동작 대신 테스트용 코드가 실행되도록 만듭니다 [11, 12].
|
||||
* **링크 접점 (Link Seams)**: 컴파일 후 중간 코드를 엮어 완전한 프로그램을 만드는 링커(Linker) 단계에서 발생하는 접점입니다 [13]. Java의 경우 `classpath`를 변경하여 원본 클래스 대신 테스트용 클래스를 로드하게 할 수 있고, C/C++에서는 테스트용 라이브러리를 스텁(Stub)으로 만들어 빌드 시 프로덕션 라이브러리 대신 연결(Link)되게 할 수 있습니다 [14, 15].
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
* **유형에 따른 명시성과 유지보수성의 차이**: 접점 중 가장 명시적이고 권장되는 방식은 객체 접점(Object Seams)입니다 [16]. 반면 전처리 접점과 링크 접점은 프로그램 소스 텍스트 내부가 아니라 빌드 스크립트나 IDE 설정 같은 '외부'에 활성화 지점을 두기 때문에 눈에 띄기 어렵습니다 [6, 16]. 이로 인해 이러한 접점들에 의존하여 작성된 테스트는 유지보수하기가 매우 까다로울 수 있으며, 다른 대안이 없고 의존성이 시스템 전체에 퍼져있는 제한적인 경우에만 사용하는 것이 바람직합니다 [16].
|
||||
* **초기 설계의 미학적 손실 감수**: 레거시 코드를 테스트 하네스(Test Harness) 안으로 가져오기 위해 접점을 만들고 의존성을 분리하는 과정은 불가피하게 코드를 부분적으로 더 지저분하게 만들 수도 있습니다 [17]. 하지만 이는 시스템을 치유하기 위한 외과 수술과 같으므로, 코드를 더 건강한 상태(테스트 가능한 상태)로 만들기 위해서는 일시적인 심미성 하락을 감수해야 합니다 [17, 18].
|
||||
* **테스트와 프로덕션 환경의 혼동 주의**: 링크 접점 등을 사용할 때는 시스템이 테스트 환경에서 동작하는지 프로덕션 환경에서 동작하는지 그 차이를 명확히 구분 및 관리하여 혼란을 방지해야 합니다 [6].
|
||||
### 매 정의
|
||||
- 매 place where you can alter behavior without editing in place.
|
||||
- 매 enabling point: 매 그 seam을 매 어떻게 활성화하는지 결정.
|
||||
|
||||
---
|
||||
*Last updated: 2026-05-03*
|
||||
### 매 3 종류 (Feathers)
|
||||
1. **Preprocessing Seam** — compile/macro/언어 전처리 (C/C++ `#define`).
|
||||
2. **Link Seam** — link-time substitution (매 alt library, jest module mock).
|
||||
3. **Object Seam** — polymorphism (매 interface/subclass).
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
### 매 응용
|
||||
1. 매 legacy에 매 test 추가 — 매 substitute dependency.
|
||||
2. 매 hexagonal port — 매 object seam.
|
||||
3. 매 feature flag — 매 conditional seam.
|
||||
|
||||
> *(TODO: 한 문장으로 핵심 통찰을 작성. "X는 Y 조건에서 Z 효과를 낸다" 구조 권장.)*
|
||||
## 💻 패턴
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 Object Seam — interface 추출
|
||||
```typescript
|
||||
// X — 매 직접 의존
|
||||
class OrderService {
|
||||
place(o: Order) {
|
||||
new SmtpMailer().send(o.user, "ordered"); // 매 hard-wired
|
||||
}
|
||||
}
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
|
||||
- **Parent:** [[10_Wiki/Topics]]
|
||||
- **Related:** *(TODO: 최소 2개)*
|
||||
- **Opposite / Trade-off:** *(TODO)*
|
||||
- **Raw Source:** 직접 입력
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
// O — 매 object seam
|
||||
interface Mailer { send(to: string, msg: string): void; }
|
||||
class OrderService {
|
||||
constructor(private mailer: Mailer) {}
|
||||
place(o: Order) { this.mailer.send(o.user, "ordered"); }
|
||||
}
|
||||
// 매 test에서 fake Mailer 주입.
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### 매 Link Seam — Jest module mock
|
||||
```typescript
|
||||
// orderService.ts
|
||||
import { sendEmail } from "./mailer";
|
||||
export function place(o: Order) { sendEmail(o.user, "ordered"); }
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
// orderService.test.ts
|
||||
import { place } from "./orderService";
|
||||
jest.mock("./mailer", () => ({ sendEmail: jest.fn() }));
|
||||
import { sendEmail } from "./mailer";
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
test("places", () => {
|
||||
place({ user: "a@b.com" } as any);
|
||||
expect(sendEmail).toHaveBeenCalledWith("a@b.com", "ordered");
|
||||
});
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### 매 Preprocessing Seam — TS compiler hook
|
||||
```typescript
|
||||
// 매 build-time substitution (매 e.g., babel plugin / tsx loader)
|
||||
// __ENV__ macro 가 매 build 시 replace
|
||||
declare const __TEST__: boolean;
|
||||
export function log(msg: string) {
|
||||
if (__TEST__) return;
|
||||
console.log(msg);
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### 매 React Context seam
|
||||
```tsx
|
||||
const ApiContext = createContext<Api>(realApi);
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
// 매 production
|
||||
<ApiContext.Provider value={realApi}><App /></ApiContext.Provider>
|
||||
|
||||
// 매 test (Storybook/jsdom)
|
||||
<ApiContext.Provider value={fakeApi}><App /></ApiContext.Provider>
|
||||
```
|
||||
|
||||
### 매 NodeJS DI container seam (NestJS)
|
||||
```typescript
|
||||
// 매 production
|
||||
@Module({ providers: [{ provide: "Mailer", useClass: SmtpMailer }] })
|
||||
class AppModule {}
|
||||
|
||||
// 매 test
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
providers: [OrderService, { provide: "Mailer", useValue: { send: jest.fn() } }],
|
||||
}).compile();
|
||||
```
|
||||
|
||||
### 매 Wrap method (Feathers technique)
|
||||
```typescript
|
||||
// X — private method 가 매 hard-coded
|
||||
class OrderService {
|
||||
place(o: Order) { this.notify(o); /* ... */ }
|
||||
private notify(o: Order) { new SmtpMailer().send(o.user, "ordered"); }
|
||||
}
|
||||
|
||||
// O — 매 protected → subclass에서 override
|
||||
class OrderService {
|
||||
place(o: Order) { this.notify(o); /* ... */ }
|
||||
protected notify(o: Order) { new SmtpMailer().send(o.user, "ordered"); }
|
||||
}
|
||||
class TestOrderService extends OrderService {
|
||||
protected notify() { /* swallow */ }
|
||||
}
|
||||
```
|
||||
|
||||
### 매 Feature flag seam
|
||||
```typescript
|
||||
const flags = await flagClient.evaluate("new-checkout", { user });
|
||||
const checkout = flags ? new NewCheckout() : new LegacyCheckout();
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Seam |
|
||||
|---|---|
|
||||
| 매 OOP + DI 가능 | Object Seam (interface). |
|
||||
| 매 legacy without DI | Link Seam (module mock). |
|
||||
| 매 C/C++ 매 macro | Preprocessing Seam. |
|
||||
| 매 React component | Context seam. |
|
||||
| 매 cross-cutting toggle | Feature flag seam. |
|
||||
|
||||
**기본값**: 매 Object Seam — 매 testability + 매 long-term cleanest.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Working Effectively with Legacy Code]] · [[Refactoring]]
|
||||
- 변형: [[Object Seam (객체 접점)]] · [[Link Seam (링크 접점)]] · [[Preprocessing Seam (전처리 접점)]]
|
||||
- 응용: [[Dependency Injection]] · [[Test Doubles]] · [[Hexagonal Architecture]]
|
||||
- Adjacent: [[Scratch Refactoring (스크래치 리팩토링)]] · [[Characterization Tests]] · [[Mock Object]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 legacy에 매 test 끼워넣기, 매 dependency 분리, 매 refactor 진입점 식별.
|
||||
**언제 X**: 매 greenfield (매 처음부터 DI로 설계).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **매 seam 강제 too many**: 매 abstraction noise.
|
||||
- **매 enabling point 미정**: 매 seam 만들고 매 활용 X.
|
||||
- **매 monkey-patching seam (Ruby/Python)**: 매 long-term 유지보수 X.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Feathers, *Working Effectively with Legacy Code*, 2004, Ch. 4).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Feathers 3-seam canonical + modern patterns |
|
||||
|
||||
Reference in New Issue
Block a user