Files
2nd/10_Wiki/Topic_Programming/Architecture/God-Object-Antipattern.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

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