Files
2nd/10_Wiki/Topics/DevOps_and_Security/추상화(Abstraction).md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

176 lines
6.2 KiB
Markdown

---
id: wiki-2026-0508-추상화-abstraction
title: 추상화(Abstraction)
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Abstraction, 추상화, Data Abstraction]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [software-design, fundamentals, oop, abstraction]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: any
framework: any
---
# 추상화(Abstraction)
## 매 한 줄
> **"매 essential 의 의 keep, 매 incidental 의 의 hide"**. 매 complexity management 의 의 의 의 의 핵심 의 mechanism — 매 detail 의 의 selectively 의 의 의 reveal 의 의 conceptual model 의 의 의 expose. 매 SOLID 의 D (Dependency Inversion) 의 의 의 foundation.
## 매 핵심
### 매 Abstraction 의 의 의 forms
1. **Procedural** — 매 function 의 의 의 의 의 step 의 hide.
2. **Data** — 매 representation 의 의 의 의 hide (ADT).
3. **Control** — 매 flow 의 의 의 hide (iterator, async).
4. **Type** — 매 generic / parametric polymorphism.
5. **Interface** — 매 contract 의 의 의 의 의 expose, impl 의 의 의 hide.
### 매 Levels of abstraction
- **High** — 매 business domain ("place order").
- **Mid** — 매 application logic ("validate cart").
- **Low** — 매 implementation ("HTTP POST").
- **Hardware** — 매 CPU instruction.
### 매 핵심 properties
- **Information hiding** (Parnas, 1972) — 매 client 의 의 의 의 implementation 의 의 의 X.
- **Encapsulation** — 매 state + behavior 의 의 의 의 bundle.
- **Substitutability** (LSP) — 매 abstraction 의 의 의 의 의 satisfy 의 implementation 의 의 의 의 swap 의 의 가능.
### 매 vs Encapsulation
- 매 Abstraction = 매 "what" — 매 의 logical model.
- 매 Encapsulation = 매 "how" — 매 mechanism (private, accessor).
## 💻 패턴
### 매 Procedural abstraction
```python
def calculate_invoice_total(invoice: Invoice) -> Money:
subtotal = sum_line_items(invoice.lines)
discount = apply_discounts(subtotal, invoice.coupons)
tax = compute_tax(subtotal - discount, invoice.address)
return subtotal - discount + tax
```
### 매 Data abstraction (ADT)
```python
from abc import ABC, abstractmethod
class Stack[T](ABC):
@abstractmethod
def push(self, item: T) -> None: ...
@abstractmethod
def pop(self) -> T: ...
@abstractmethod
def peek(self) -> T: ...
@abstractmethod
def is_empty(self) -> bool: ...
# 매 ArrayList 의 의 의 implementation, LinkedList 의 의 의 의 implementation — 매 swap 가능
```
### 매 Interface (contract)
```typescript
interface PaymentGateway {
charge(userId: string, amount: Money): Promise<ChargeResult>;
refund(chargeId: string): Promise<RefundResult>;
}
class StripeGateway implements PaymentGateway { /* ... */ }
class AdyenGateway implements PaymentGateway { /* ... */ }
class FakeGateway implements PaymentGateway { /* test */ }
```
### 매 Dependency inversion
```java
// 매 High-level 의 의 의 abstraction 의 의 의 의 의 depend, 매 low-level impl 의 의 의 X.
class OrderService {
private final PaymentGateway gateway; // 매 abstraction
public OrderService(PaymentGateway gw) { this.gateway = gw; }
}
```
### 매 Type abstraction (generic)
```rust
fn largest<T: PartialOrd>(list: &[T]) -> &T {
let mut largest = &list[0];
for item in list {
if item > largest { largest = item; }
}
largest
}
```
### 매 Control abstraction (iterator)
```python
def first_match(items: Iterable[T], pred: Callable[[T], bool]) -> T | None:
for item in items:
if pred(item): return item
return None
# 매 list, generator, file, stream 의 의 모두 의 의 의 work
```
### 매 Leaky abstraction (Joel Spolsky)
```python
# 매 Bad — 매 underlying TCP 의 의 의 의 의 leak
def send(msg):
try: socket.send(msg)
except ConnectionResetError: ... # 매 abstraction 의 의 의 의 의 break
# 매 Better — 매 wrap
class MessageBus:
def send(self, msg) -> SendResult:
try: self._socket.send(msg); return SendResult.OK
except: return SendResult.RETRY
```
### 매 Higher-Kinded abstraction
```scala
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
// 매 List, Option, Future 의 의 모두 의 Functor — 매 abstraction 의 의 의 매 type constructor 의 의 over
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| 매 detail 의 의 의 client 의 의 의 의 X 의 의 needed | 매 hide via 매 interface |
| 매 multiple impl 의 의 의 expected | 매 abstract class / interface |
| 매 single use, single impl | 매 직접 — 매 premature abstraction 의 X |
| 매 stable detail | 매 leak 의 의 의 의 의 fine — 매 simplicity 의 win |
| 매 cross-process boundary | 매 strong abstraction (RPC, queue) |
**기본값**: 매 rule of three — 매 셋 의 의 의 의 의 occur 의 의 의 의 abstract.
## 🔗 Graph
- 변형: [[Encapsulation]] · [[Information Hiding]] · [[Polymorphism]]
- 응용: [[SOLID]] · [[Hexagonal Architecture]] · [[Clean Architecture]]
- Adjacent: [[TypeScript 타입 시스템 (TypeScript Type System)|Type System]]
## 🤖 LLM 활용
**언제**: 매 design — 매 boundary 의 의 의 draw, 매 변경 의 의 absorb 의 의 의 abstraction layer 의 의 의 introduce.
**언제 X**: 매 single-call site, 매 prototype — 매 premature abstraction 의 의 의 cost.
## ❌ 안티패턴
- **Premature abstraction**: 매 한 implementation 의 의 의 의 의 interface 의 의 introduce — 매 noise.
- **Leaky abstraction**: 매 underlying detail 의 의 의 의 surface — 매 client 의 의 의 의 know 의 의 force.
- **God interface**: 매 모든 의 method 의 의 의 의 한 interface 의 의 — ISP 의 violation.
- **Wrong abstraction (Sandi Metz)**: 매 잘못 의 abstraction 의 의 의 duplication 의 의 보다 의 worse.
## 🧪 검증 / 중복
- Verified — Parnas (1972) "On the Criteria To Be Used in Decomposing Systems"; Joel Spolsky "Law of Leaky Abstractions"; Sandi Metz, *Practical Object-Oriented Design*.
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — abstraction forms + leaky / wrong-abstraction discussion |