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 폴더 제거.
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
---
|
||||
id: wiki-2026-0508-extract-class-클래스-추출하기
|
||||
title: Extract Class (클래스 추출하기)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Extract Class, 클래스 추출, Refactoring]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [refactoring, fowler, srp, oop]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: typescript
|
||||
framework: none
|
||||
---
|
||||
|
||||
# Extract Class (클래스 추출하기)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 too-much-doing class 의 cohesive subset 의 split"**. Extract Class 매 Fowler refactoring catalog 의 core move — 매 single class 매 multiple responsibilities 의 carry, 매 data + methods 의 cohesive cluster 의 new class 의 extract. SRP 의 enforcement.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Smell signals
|
||||
- 매 class 매 200+ lines 의 grow.
|
||||
- 매 fields 의 subset 매 always 의 used together (e.g., `street/city/zip` 의 always together).
|
||||
- 매 methods 매 disjoint groups 의 form — 매 group A methods 매 group A fields only 의 use.
|
||||
- 매 class name 매 vague — `Manager`, `Helper`, `Util`.
|
||||
|
||||
### 매 Mechanics (Fowler)
|
||||
1. 매 responsibility 의 identify — 매 split point.
|
||||
2. 매 new child class 의 create.
|
||||
3. 매 parent → child reference 의 establish.
|
||||
4. 매 fields 의 move (Move Field).
|
||||
5. 매 methods 의 move (Move Method) — 매 leaves first.
|
||||
6. 매 child interface 의 review — 매 internal exposure 의 minimize.
|
||||
7. 매 expose: 매 child 의 public 의 또는 parent-only 의 decision.
|
||||
|
||||
### 매 응용
|
||||
1. Person → Person + TelephoneNumber.
|
||||
2. Order → Order + ShippingAddress + BillingAddress.
|
||||
3. UserService → UserService + AuthService + ProfileService.
|
||||
4. GameEntity → Position + Velocity + Health (ECS).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Before — God class
|
||||
```typescript
|
||||
class Person {
|
||||
name: string;
|
||||
officeAreaCode: string;
|
||||
officeNumber: string;
|
||||
|
||||
getTelephoneNumber(): string {
|
||||
return `(${this.officeAreaCode}) ${this.officeNumber}`;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### After — Extract Class
|
||||
```typescript
|
||||
class TelephoneNumber {
|
||||
constructor(public areaCode: string, public number: string) {}
|
||||
toString(): string { return `(${this.areaCode}) ${this.number}`; }
|
||||
}
|
||||
|
||||
class Person {
|
||||
constructor(
|
||||
public name: string,
|
||||
private officeTelephone: TelephoneNumber,
|
||||
) {}
|
||||
get telephoneNumber(): string { return this.officeTelephone.toString(); }
|
||||
// delegate accessors during transition
|
||||
get officeAreaCode() { return this.officeTelephone.areaCode; }
|
||||
set officeAreaCode(v: string) { this.officeTelephone.areaCode = v; }
|
||||
}
|
||||
```
|
||||
|
||||
### Address extraction
|
||||
```typescript
|
||||
// Before
|
||||
class Order {
|
||||
customerName: string;
|
||||
street: string; city: string; zipCode: string; country: string;
|
||||
shippingCost: number;
|
||||
}
|
||||
|
||||
// After
|
||||
class Address {
|
||||
constructor(
|
||||
public street: string,
|
||||
public city: string,
|
||||
public zipCode: string,
|
||||
public country: string,
|
||||
) {}
|
||||
format(): string { return `${this.street}, ${this.city} ${this.zipCode}, ${this.country}`; }
|
||||
isInternational(home: string) { return this.country !== home; }
|
||||
}
|
||||
|
||||
class Order {
|
||||
constructor(
|
||||
public customerName: string,
|
||||
public shippingAddress: Address,
|
||||
public shippingCost: number,
|
||||
) {}
|
||||
}
|
||||
```
|
||||
|
||||
### Service split (SRP)
|
||||
```typescript
|
||||
// Before — 600 LOC
|
||||
class UserService {
|
||||
signup() { /* ... */ }
|
||||
login() { /* ... */ }
|
||||
resetPassword() { /* ... */ }
|
||||
updateProfile() { /* ... */ }
|
||||
uploadAvatar() { /* ... */ }
|
||||
getPreferences() { /* ... */ }
|
||||
}
|
||||
|
||||
// After
|
||||
class AuthService {
|
||||
signup() {} login() {} resetPassword() {}
|
||||
}
|
||||
class ProfileService {
|
||||
updateProfile() {} uploadAvatar() {} getPreferences() {}
|
||||
}
|
||||
// UserService 의 orchestration only 의 keep
|
||||
```
|
||||
|
||||
### ECS-style field group extraction
|
||||
```typescript
|
||||
// Before — game entity 의 carries everything
|
||||
class Enemy {
|
||||
x: number; y: number; vx: number; vy: number;
|
||||
hp: number; maxHp: number; armor: number;
|
||||
spriteId: string; animFrame: number;
|
||||
}
|
||||
|
||||
// After — components
|
||||
class Position { constructor(public x: number, public y: number) {} }
|
||||
class Velocity { constructor(public vx: number, public vy: number) {} }
|
||||
class Health { constructor(public hp: number, public maxHp: number, public armor = 0) {} }
|
||||
class Sprite { constructor(public id: string, public frame = 0) {} }
|
||||
|
||||
class Enemy {
|
||||
constructor(
|
||||
public position: Position,
|
||||
public velocity: Velocity,
|
||||
public health: Health,
|
||||
public sprite: Sprite,
|
||||
) {}
|
||||
}
|
||||
```
|
||||
|
||||
### Incremental migration via delegation
|
||||
```typescript
|
||||
class Person {
|
||||
private _phone = new TelephoneNumber('', '');
|
||||
// Old API 의 keep working
|
||||
get officeNumber() { return this._phone.number; }
|
||||
set officeNumber(v: string) { this._phone.number = v; }
|
||||
// New API 의 prefer
|
||||
get phone() { return this._phone; }
|
||||
}
|
||||
// Phase 1: delegate. Phase 2: callers migrate to .phone. Phase 3: remove old getters.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Class < 100 LOC, single concept | 매 extract 매 X — 매 premature |
|
||||
| Field subset always 의 together | 매 Extract Class |
|
||||
| Two distinct responsibilities | 매 Extract Class + Move Method |
|
||||
| Component reuse 의 needed (game) | 매 ECS-style components 의 extract |
|
||||
| Public API 의 break 의 dangerous | 매 delegating accessors 의 transition |
|
||||
|
||||
**기본값**: 매 class 매 2 의 distinct responsibility 의 carry 의 extract — 매 cohesion > 1 class.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Refactoring_Best_Practices|Refactoring]] · [[SOLID]]
|
||||
- 응용: [[Single Responsibility Principle (SRP)|Single-Responsibility-Principle]] · [[Entity-Component-System]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 class 매 200+ LOC, 매 multiple distinct concerns. Field cluster 의 always 의 co-occur. Test setup 매 unrelated mocks 의 require.
|
||||
**언제 X**: 매 small DTO. 매 abstraction 의 cost > readability gain (매 over-extraction).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Anemic extraction**: 매 fields only 의 move, 매 methods 매 parent 의 stay — 매 just data bag 의 result. Methods 의 follow 의 must.
|
||||
- **Reverse coupling**: 매 child 매 parent 의 reference back — 매 cyclic dependency. One-way reference 의 keep.
|
||||
- **Premature extract**: 매 50 LOC class 의 split — 매 navigation overhead > clarity.
|
||||
- **Public sprawl**: 매 child 의 immediately public — 매 hide 매 first, 매 expose 의 demand 의 occur 시.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Fowler "Refactoring" 2nd ed., Ch. 7).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Extract Class refactoring 의 mechanics + 5 patterns |
|
||||
Reference in New Issue
Block a user