Files
2nd/10_Wiki/Topic_Programming/AI_and_ML/Anaemic Domain Model.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

6.4 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-anaemic-domain-model Anaemic Domain Model 10_Wiki/Topics verified self
빈약한 도메인 모델
transaction script
getter-setter model
data class
none B 0.88 applied
ddd
anti-pattern
anaemic
transaction-script
oop
domain-model
architecture
2026-05-10 pending
language framework
Java / C# / TypeScript DDD / Clean Architecture

Anaemic Domain Model

📌 한 줄 통찰

"매 data 만 의 class + 매 logic 의 service 의 split". Martin Fowler 가 anti-pattern 가 — 매 OOP 의 procedural 화. 매 simple CRUD OK 가, 매 complex domain 의 maintainability 망가짐. DDD 의 Rich Domain Model 가 답.

📖 핵심

매 정의

  • 매 entity class 가 getter / setter 만.
  • 매 business logic 가 service / manager class.
  • 매 data ≠ behavior 의 OO 위반.

Fowler 의 비판 (2003)

"It looks like the real thing... but when you look at the behavior, you realize there is hardly any behavior on these objects, making them little more than bags of getters and setters."

→ 매 procedural 의 disguise.

매 anti-pattern 의 이유

  1. OOP 의 위반: 매 encapsulation X, data ≠ behavior.
  2. 매 invariant 의 violate: 매 entity 의 invariant 의 service 가 알아야.
  3. Logic 의 분산: 매 같은 entity 의 logic 의 매 service 의 spread.
  4. Test 어려움: 매 service 의 entity mock 의 burden.
  5. DDD 의 Bounded Context 의 약화.

Anaemic vs Rich

Anaemic

class Order {
  id: string;
  items: Item[];
  total: number;
  status: 'pending' | 'paid' | 'shipped';
  // 매 getter / setter 만.
}

class OrderService {
  pay(order: Order, amount: number) {
    if (order.status !== 'pending') throw new Error();
    if (amount < order.total) throw new Error();
    order.status = 'paid';
    // 매 logic 의 service.
  }
}

→ 매 invariant 의 service 가 알아야. 매 다른 service 의 같은 logic 반복.

Rich

class Order {
  private status: 'pending' | 'paid' | 'shipped' = 'pending';
  
  pay(amount: Money) {
    if (this.status !== 'pending') throw new InvalidOrderState();
    if (amount.isLessThan(this.total)) throw new InsufficientPayment();
    this.status = 'paid';
    this.events.push(new OrderPaid(this.id));
  }
  
  ship() {
    if (this.status !== 'paid') throw new InvalidOrderState();
    this.status = 'shipped';
  }
}

→ 매 invariant 의 entity 자체. 매 logic 의 cohesive.

매 OK 가 case

  • CRUD-only: 매 simple form / report. 매 logic 거의 없음.
  • Microservice 의 small: 매 single domain 의 작은 service.
  • Reporting / analytics: 매 read-only.
  • DTO: 매 transport 의 data 만.

case

  • Complex domain: 매 ordering, billing, accounting.
  • 매 invariant 의 많음: 매 entity 의 rule.
  • Long-lived codebase: 매 maintenance.
  • Team 의 큰: 매 logic 의 spread → bug.

DDD 의 답

  • Aggregate: 매 entity 의 root 가 invariant 보호.
  • Value Object: 매 immutable + behavior.
  • Domain Service: 매 entity 의 across 의 logic 만.
  • Repository: 매 persistence.
  • Domain Event: 매 state change 의 명시.

💻 패턴

Aggregate root (DDD)

class CartAggregate {
  private items: Map<ProductId, CartItem> = new Map();
  
  add(productId: ProductId, qty: number) {
    if (qty <= 0) throw new InvalidQuantity();
    const existing = this.items.get(productId);
    if (existing) existing.increment(qty);
    else this.items.set(productId, new CartItem(productId, qty));
  }
  
  remove(productId: ProductId) {
    if (!this.items.has(productId)) throw new ItemNotFound();
    this.items.delete(productId);
  }
  
  total(prices: Map<ProductId, Money>): Money {
    return [...this.items.values()].reduce(
      (sum, item) => sum.add(prices.get(item.productId)!.times(item.qty)),
      Money.zero('USD'),
    );
  }
}

Value Object (immutable + behavior)

class Money {
  constructor(
    public readonly amount: bigint,
    public readonly currency: string,
  ) {}
  
  add(other: Money): Money {
    if (this.currency !== other.currency) throw new CurrencyMismatch();
    return new Money(this.amount + other.amount, this.currency);
  }
  
  times(n: number): Money { return new Money(this.amount * BigInt(n), this.currency); }
  
  isLessThan(other: Money): boolean {
    if (this.currency !== other.currency) throw new CurrencyMismatch();
    return this.amount < other.amount;
  }
  
  static zero(currency: string) { return new Money(0n, currency); }
}

Domain event

class Order {
  private events: DomainEvent[] = [];
  
  pay(amount: Money) {
    // ...
    this.events.push(new OrderPaid(this.id, amount, new Date()));
  }
  
  pullEvents(): DomainEvent[] {
    const out = this.events;
    this.events = [];
    return out;
  }
}

// Repository 가 save 시 publish.

🤔 결정 기준

상황 모델
Simple CRUD Anaemic OK
Complex business rule Rich (DDD)
Microservice (small) Anaemic OK
Microservice (core domain) Rich
DTO / API contract Anaemic (data only)
Long-lived codebase Rich

기본값: 매 core domain = Rich. 매 supporting = Anaemic 가 OK.

🔗 Graph

🤖 LLM 활용

언제: 매 backend service design 의 review. 매 DDD 의 적용 결정. 매 legacy 의 refactor. 언제 X: 매 quick prototype. 매 simple admin tool.

안티패턴

  • 모든 domain 의 anaemic: 매 OOP 가치 X.
  • Service 의 logic 폭발: 매 god object.
  • Invariant 의 service / controller 분산: 매 inconsistent.
  • 모든 domain 의 rich: 매 over-engineering. 매 simple CRUD 의 burden.
  • Anaemic 의 ORM 강제: 매 framework 의 lock-in.

🧪 검증 / 중복

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Fowler 비판 + Rich 예제 + Aggregate code