Files
2nd/10_Wiki/Topics/Domain_Programming/Architecture/God-Object-Antipattern.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

5.8 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-god-object-antipattern God Object Antipattern 10_Wiki/Topics verified self
God Class
Blob
Monster Class
none A 0.9 applied
architecture
antipattern
oop
refactoring
code-smell
2026-05-10 pending
language framework
typescript language-agnostic

God Object Antipattern

매 한 줄

"매 single class/module 의 too many responsibilities 의 absorption 의 통한 maintainability 의 collapse". 매 Brown et al. "AntiPatterns" (1998) 의 catalog, 매 procedural code 의 OOP 로 의 lift-and-shift 의 결과 — 매 modern microservices 시대 의 "God Service" 로 의 mutation.

매 핵심

매 Symptoms

  • 1000+ LOC class, 50+ methods.
  • 매 unrelated domain 의 mix (User + Order + Payment + Logging).
  • 매 import 의 fan-in 의 high — 매 module 의 reference 의 most.
  • Test 의 setup 의 100+ lines mock.
  • Git log 의 churn 의 highest hot-spot.

매 Causes

  • SRP (Single Responsibility) 의 violation.
  • Premature centralization ("Manager", "Controller", "Helper" suffix).
  • Feature 의 incremental 의 add 의 always-cheapest-place 의 dump.
  • Refactoring fear (test 의 X, dependency 의 web).

매 응용 (detection)

  1. SonarQube "Brain Class" rule.
  2. Lizard / radon 의 cyclomatic + LOC metric.
  3. CodeScene hotspot map.

💻 패턴

Smell — God Class

// 🚨 God Object
export class ApplicationManager {
  users: User[] = [];
  orders: Order[] = [];
  cart: Cart;
  paymentGateway: Stripe;
  logger: Logger;
  cache: Redis;
  // ... 47 more fields

  registerUser(...) { /* 80 lines */ }
  authenticateUser(...) { /* 60 lines */ }
  createOrder(...) { /* 120 lines, calls payment, cache, log */ }
  refundOrder(...) { /* 90 lines */ }
  sendEmail(...) { /* 40 lines */ }
  generateReport(...) { /* 200 lines */ }
  // ... 50 more methods
}

Refactor — Extract Class (SRP)

export class UserService {
  constructor(private repo: UserRepository, private hasher: PasswordHasher) {}
  async register(input: RegisterInput) { /* ... */ }
  async authenticate(creds: Credentials) { /* ... */ }
}

export class OrderService {
  constructor(
    private repo: OrderRepository,
    private payment: PaymentGateway,
    private events: EventBus,
  ) {}
  async create(input: CreateOrderInput) { /* ... */ }
  async refund(orderId: string) { /* ... */ }
}

export class ReportingService { /* ... */ }

Replace Conditional with Polymorphism

// Before: god method 의 switch
processPayment(method: string, amount: number) {
  if (method === 'card') { /* ... */ }
  else if (method === 'paypal') { /* ... */ }
  else if (method === 'crypto') { /* ... */ }
}

// After: Strategy
interface PaymentMethod { charge(amount: number): Promise<Receipt>; }
class CardPayment implements PaymentMethod { /* ... */ }
class PayPalPayment implements PaymentMethod { /* ... */ }
class CryptoPayment implements PaymentMethod { /* ... */ }

class PaymentService {
  constructor(private methods: Map<string, PaymentMethod>) {}
  charge(method: string, amount: number) {
    return this.methods.get(method)!.charge(amount);
  }
}

Extract Aggregate (DDD)

// God 의 split → Aggregate Root + Value Objects
export class Order {
  private constructor(
    public readonly id: OrderId,
    private items: LineItem[],
    private status: OrderStatus,
  ) {}

  static create(customerId: CustomerId, items: LineItem[]): Order { /* ... */ }
  addItem(item: LineItem) { /* invariant 의 enforce */ }
  confirm(): DomainEvent[] { /* ... */ }
}

ESLint Rule (max-lines-per-function/class)

{
  "rules": {
    "max-lines": ["error", { "max": 400, "skipBlankLines": true }],
    "max-lines-per-function": ["error", 60],
    "complexity": ["error", 10]
  }
}

SonarQube Detection

sonar.cpd.exclusions=**/*.test.ts
# Rule: java:S2972 (Inner classes should not have too many lines)
# Rule: typescript:S138 (Functions should not have too many lines)
# Rule: common:DuplicatedBlocks

매 결정 기준

상황 Approach
Class > 500 LOC Extract Class by responsibility
Method > 60 LOC Extract Method, Replace Temp with Query
Long parameter list Introduce Parameter Object
Switch on type Replace Conditional with Polymorphism
Cross-domain mix Extract Bounded Context (DDD)

기본값: 매 SRP — 매 class 의 one reason to change.

🔗 Graph

🤖 LLM 활용

언제: god class 의 detect, extract-class 의 refactor 의 suggest, responsibility 의 cluster 의 propose. 언제 X: 매 large refactor 의 final commit (test coverage 의 human verification 필수).

안티패턴

  • Manager/Helper suffix: 매 dumping ground 의 invitation.
  • Static God: Utils static class 의 grow → 매 testability 의 destroy.
  • God Service: microservice 시대 의 god — single service 의 매 domain 의 own.
  • Refactor without tests: 매 god 의 split 의 시 behavior 의 break 의 silent.
  • Premature split: 매 50 LOC class 의 over-decompose → 매 anemic + indirection 의 hell.

🧪 검증 / 중복

  • Verified (Brown et al. "AntiPatterns" 1998, Fowler "Refactoring" 2nd ed., SonarSource rules).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — god object antipattern 의 full content