Files
2nd/10_Wiki/Topic_Programming/Architecture/SOLID Principles.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

161 lines
5.1 KiB
Markdown

---
id: wiki-2026-0508-solid-principles
title: SOLID Principles
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [SOLID, SOLID 원칙, OOD Principles]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [oop, design-principles, clean-code]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: typescript
framework: none
---
# SOLID Principles
## 매 한 줄
> **"매 5개 OOD 원칙 — 매 변경에 견디는 클래스 설계의 기본기"**. Robert C. Martin이 2000년대 초 정리한 5원칙(SRP/OCP/LSP/ISP/DIP)은 매 객체지향 설계의 lingua franca. 2026년에도 매 TypeScript/Kotlin/Swift 코드 review의 매 첫 lens.
## 매 핵심
### 매 5원칙
- **S**RP — Single Responsibility: 매 클래스는 매 한 가지 변경 이유.
- **O**CP — Open/Closed: 매 확장에 열려, 수정에 닫혀.
- **L**SP — Liskov Substitution: 매 서브타입은 매 부모 대체 가능.
- **I**SP — Interface Segregation: 매 client는 매 unused method 의존 X.
- **D**IP — Dependency Inversion: 매 추상에 의존, 구체에 의존 X.
### 매 적용 원리
- **결합도 ↓**: 매 DIP/ISP가 핵심.
- **응집도 ↑**: 매 SRP가 driver.
- **다형성 안전성**: 매 LSP/OCP.
### 매 응용
1. Hexagonal/Clean Architecture 의 layering 근거.
2. DI container (Spring, NestJS) 의 설계 정당성.
3. AI agent tool interface 분리 (ISP).
## 💻 패턴
### SRP — 책임 분리
```typescript
// X — 매 두 책임 (저장 + 알림)
class Order {
save() { db.insert(this); }
notify() { mailer.send(this.user, "ordered"); }
}
// O
class Order { /* domain only */ }
class OrderRepo { save(o: Order) { db.insert(o); } }
class OrderNotifier { notify(o: Order) { mailer.send(o.user, "ordered"); } }
```
### OCP — 확장 가능 구조
```typescript
interface Discount { apply(price: number): number; }
class SeasonalDiscount implements Discount { apply(p: number) { return p * 0.9; } }
class VipDiscount implements Discount { apply(p: number) { return p * 0.8; } }
class Checkout {
constructor(private d: Discount) {}
total(p: number) { return this.d.apply(p); }
}
// 새 할인 추가 = 새 구현만, Checkout 수정 X.
```
### LSP — 안전한 대체
```typescript
// X — Square가 Rectangle invariant 깨뜨림
class Rectangle { setW(w:number){} setH(h:number){} }
class Square extends Rectangle { setW(w:number){ super.setW(w); super.setH(w); } }
// O — 분리된 계층
interface Shape { area(): number; }
class Rectangle implements Shape { constructor(public w:number, public h:number){} area(){ return this.w*this.h; } }
class Square implements Shape { constructor(public s:number){} area(){ return this.s*this.s; } }
```
### ISP — fat interface 분리
```typescript
// X
interface Worker { code(): void; eat(): void; }
// O — robot은 eat 안함
interface Codeable { code(): void; }
interface Eatable { eat(): void; }
class Human implements Codeable, Eatable { code(){} eat(){} }
class Robot implements Codeable { code(){} }
```
### DIP — 의존성 역전
```typescript
// 매 high-level은 abstraction에 의존
interface Logger { log(msg: string): void; }
class ConsoleLogger implements Logger { log(m:string){ console.log(m); } }
class OrderService {
constructor(private logger: Logger) {} // 매 추상 의존
place() { this.logger.log("ordered"); }
}
new OrderService(new ConsoleLogger()).place();
```
### React/Hook 적용 (SRP + DIP)
```typescript
// 매 hook 분리 + DI
function useOrders(repo: OrderRepo = defaultRepo) {
return useQuery(["orders"], () => repo.list());
}
```
### NestJS DI (DIP 자연스러움)
```typescript
@Injectable()
class OrderService {
constructor(@Inject("OrderRepo") private repo: OrderRepo) {}
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| 매 작은 script | 매 SOLID 강제 X. 매 over-engineering 위험. |
| 매 production service | 매 5원칙 routinely 적용. |
| 매 plugin/extension architecture | OCP+DIP 우선. |
| 매 legacy refactor | SRP부터. 매 클래스 분리. |
**기본값**: 매 production code → 5원칙 review. 매 prototype → 무시 OK.
## 🔗 Graph
- 부모: [[Clean Code]]
- 응용: [[Hexagonal Architecture]] · [[Clean Architecture]] · [[Dependency Injection]]
- Adjacent: [[Single Responsibility Principle (SRP)]] · [[Open Closed Principle]]
## 🤖 LLM 활용
**언제**: 매 코드 review, 매 architecture 결정 정당화, 매 refactor 우선순위 산정.
**언제 X**: 매 throwaway script, 매 학습용 toy code.
## ❌ 안티패턴
- **SOLID 광신**: 매 모든 클래스를 5원칙 강제 → 매 over-abstraction.
- **SRP 오해**: 매 "한 메서드 = 한 클래스" 로 해석.
- **DIP 표면적 적용**: 매 interface만 만들고 매 구현 1개 → 매 abstraction noise.
- **LSP 명목적 통과**: 매 throw NotImplemented로 매 LSP 우회.
## 🧪 검증 / 중복
- Verified (R.C. Martin "Agile Software Development", Clean Architecture).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — 5원칙 working code patterns 추가 |