docs(10_Wiki): Topic_Business/General/Graphic/Programming을 Topics/ 하위로 이동
최상위 10_Wiki/Topic_*였던 4개 카테고리 폴더를 10_Wiki/Topics/Topic_* 로 재배치. 콘텐츠 변경 없음(순수 폴더 이동) — Topics/ 하위 나머지 폴더는 이미 지난 커밋에서 전부 정리된 상태(잔존 항목은 에이전트 운영 상태 및 사용자가 보존을 요청한 업데이트0615/무제 3.canvas 뿐).
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
---
|
||||
id: wiki-2026-0508-object-oriented-programming
|
||||
title: Object-Oriented Programming (OOP)
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [OOP, Object Oriented Programming, 객체지향, 객체지향 프로그래밍]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [oop, programming-paradigm, design, architecture]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: java-typescript-cpp
|
||||
framework: multi
|
||||
---
|
||||
|
||||
# Object-Oriented Programming (OOP)
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 data + behavior를 object로 묶고, polymorphism으로 동작을 추상화하는 패러다임."**. Simula 67 (1967) → Smalltalk (1972) → C++ (1985) → Java (1995) → 매 mainstream. 2026 현재는 OO + FP hybrid가 dominant — Java records, Kotlin data class, TypeScript readonly class, Rust trait이 그 증거.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 4 pillar
|
||||
- **Encapsulation**: 매 internal state hide, expose behavior — `private` field + `public` method.
|
||||
- **Inheritance**: 매 reuse + specialize — 단 *favor composition over inheritance* (GoF).
|
||||
- **Polymorphism**: 매 same interface, different impl — virtual dispatch · duck typing.
|
||||
- **Abstraction**: 매 essential 만 expose — interface · abstract class.
|
||||
|
||||
### 매 SOLID (Robert C. Martin)
|
||||
- **S**ingle Responsibility — 매 class one reason to change.
|
||||
- **O**pen/Closed — 매 extend without modify.
|
||||
- **L**iskov Substitution — 매 subtype substitutable.
|
||||
- **I**nterface Segregation — 매 small focused interfaces.
|
||||
- **D**ependency Inversion — 매 depend on abstraction.
|
||||
|
||||
### 매 응용
|
||||
1. Domain-Driven Design — Entity, Value Object, Aggregate.
|
||||
2. GUI framework — Component hierarchy (React class component, Qt widget).
|
||||
3. Game engine — Entity-Component-System (modern hybrid).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Encapsulation — invariant 보장
|
||||
```java
|
||||
public final class Money {
|
||||
private final BigDecimal amount;
|
||||
private final Currency currency;
|
||||
public Money(BigDecimal a, Currency c) {
|
||||
if (a.signum() < 0) throw new IllegalArgumentException("negative");
|
||||
this.amount = a; this.currency = c;
|
||||
}
|
||||
public Money add(Money other) {
|
||||
if (!currency.equals(other.currency))
|
||||
throw new IllegalStateException("currency mismatch");
|
||||
return new Money(amount.add(other.amount), currency);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Polymorphism — strategy
|
||||
```typescript
|
||||
interface Shipping {
|
||||
calculate(weight: number): number;
|
||||
}
|
||||
class StandardShipping implements Shipping {
|
||||
calculate(w: number) { return w * 5; }
|
||||
}
|
||||
class ExpressShipping implements Shipping {
|
||||
calculate(w: number) { return w * 12 + 10; }
|
||||
}
|
||||
function totalCost(items: Item[], shipping: Shipping): number {
|
||||
const w = items.reduce((s, i) => s + i.weight, 0);
|
||||
return items.reduce((s, i) => s + i.price, 0) + shipping.calculate(w);
|
||||
}
|
||||
```
|
||||
|
||||
### Composition over inheritance
|
||||
```typescript
|
||||
// BAD: deep hierarchy
|
||||
class Animal {}
|
||||
class Dog extends Animal {}
|
||||
class FlyingDog extends Dog {} // ???
|
||||
|
||||
// GOOD: composition
|
||||
class Animal {
|
||||
constructor(
|
||||
private mover: Movement,
|
||||
private noise: NoiseMaker,
|
||||
) {}
|
||||
move() { return this.mover.move(); }
|
||||
speak() { return this.noise.sound(); }
|
||||
}
|
||||
const dog = new Animal(new Walking(), new Bark());
|
||||
const bird = new Animal(new Flying(), new Chirp());
|
||||
```
|
||||
|
||||
### Abstract class + template method
|
||||
```java
|
||||
public abstract class HttpHandler {
|
||||
public final Response handle(Request req) {
|
||||
if (!authenticate(req)) return Response.unauthorized();
|
||||
var data = process(req);
|
||||
return render(data);
|
||||
}
|
||||
protected abstract boolean authenticate(Request req);
|
||||
protected abstract Object process(Request req);
|
||||
protected Response render(Object data) {
|
||||
return Response.ok().json(data);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Modern hybrid — record (Java 21) / data class
|
||||
```java
|
||||
public record User(UserId id, Email email, String name) {
|
||||
public User { // compact constructor
|
||||
Objects.requireNonNull(email);
|
||||
if (name.isBlank()) throw new IllegalArgumentException();
|
||||
}
|
||||
public User withName(String n) { return new User(id, email, n); }
|
||||
}
|
||||
```
|
||||
|
||||
### Trait-based OOP (Rust)
|
||||
```rust
|
||||
trait Drawable {
|
||||
fn draw(&self, canvas: &mut Canvas);
|
||||
fn bounds(&self) -> Rect;
|
||||
}
|
||||
struct Circle { center: Point, r: f32 }
|
||||
impl Drawable for Circle {
|
||||
fn draw(&self, c: &mut Canvas) { c.circle(self.center, self.r); }
|
||||
fn bounds(&self) -> Rect { Rect::around(self.center, self.r) }
|
||||
}
|
||||
fn render_all(shapes: &[Box<dyn Drawable>], canvas: &mut Canvas) {
|
||||
for s in shapes { s.draw(canvas); }
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Domain with complex invariants | OOP + DDD entities/VO |
|
||||
| Pure data transformation | FP (immutable + pure functions) |
|
||||
| Plug-in / extensibility | Interface + DI |
|
||||
| State machine | OOP class with explicit states |
|
||||
| Hot loop, ECS scale | Data-Oriented (avoid virtual dispatch) |
|
||||
|
||||
**기본값**: hybrid OOP+FP — value objects immutable, services with interfaces, pure functions for transforms.
|
||||
|
||||
## 🔗 Graph
|
||||
- 변형: [[Functional_Programming]] · [[Procedural-Architecture-Systems]] · [[ECS]]
|
||||
- 응용: [[SOLID Principles]] · [[Polymorphism (다형성)]] · [[Object Seam (객체 접점)]] · [[Bounded_Context]]
|
||||
- Adjacent: [[High-Cohesion-Low-Coupling]] · [[Dependency_Inversion_Principle]] · [[Hexagonal_Architecture_Ports_and_Adapters]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: business domain modeling, framework/library design, GUI hierarchy, plug-in architecture.
|
||||
**언제 X**: hot numerical loop (DOD better), pure transform pipeline (FP cleaner), 1-file script.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **God Object**: 매 모든 책임 한 class — SRP 위반.
|
||||
- **Anemic Domain Model**: data only, behavior in service — OOP 무력화.
|
||||
- **Deep inheritance (4+ levels)**: 매 fragile base class.
|
||||
- **Premature interface**: 매 single impl을 interface로 — YAGNI.
|
||||
- **Setter everywhere**: 매 invariant 깨짐 — immutable + factory.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (GoF *Design Patterns* 1994, Martin *Clean Code* 2008, Evans *DDD* 2003, Java/Kotlin/Rust 2026 docs).
|
||||
- 신뢰도 A.
|
||||
- Duplicates: `객체_지향_프로그래밍(OOP).md`, `객체_지향_프로그래밍_Object-Oriented_Programming,_OOP.md` should redirect here.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — canonical OOP doc (4 pillars + SOLID + modern hybrid) |
|
||||
Reference in New Issue
Block a user