"매 behavior + state 의 cohesive object 의 cluster". 매 OO architecture 의 system 의 collaborating object 의 graph 의 model — 매 modern stack 의 DDD + Clean/Hexagonal + SOLID 의 layered.
매 핵심
매 Layered architecture
Domain: 매 entity, value object, aggregate root.
Application: 매 use case, 매 thin orchestration.
Infrastructure: 매 DB, queue, external API adapter.
Interface: 매 HTTP, CLI, gRPC.
Rule: 매 dependency 의 inward 의 only (Clean Architecture).
매 Building blocks (DDD)
Entity: identity 의 have (User#42).
Value object: identity 의 X, immutable (Money(100, USD)).
Aggregate: consistency boundary, 매 root 의 only 의 외부 의 expose.
Repository: aggregate 의 persist abstraction.
Service: stateless behavior 의 cross-aggregate.
Event: aggregate state change 의 broadcast.
매 Design principles
SOLID: SRP, OCP, LSP, ISP, DIP.
Composition over inheritance: 매 has-a > is-a.
Tell, don't ask: 매 behavior 의 object 의 push.
Law of Demeter: 매 don't talk to strangers.
매 응용
E-commerce checkout (Order aggregate).
Banking transfer (Account + Transaction).
SaaS multi-tenant (Tenant boundary).
Game state machine.
💻 패턴
Aggregate root + repository (Python)
fromdataclassesimportdataclass,fieldfromdecimalimportDecimalfromuuidimportUUID,uuid4@dataclass(frozen=True)classMoney:# value objectamount:Decimalcurrency:strdef__add__(self,o:"Money")->"Money":ifself.currency!=o.currency:raiseValueErrorreturnMoney(self.amount+o.amount,self.currency)@dataclassclassOrderLine:sku:strqty:intprice:MoneyclassOrder:# aggregate rootdef__init__(self,id:UUID,lines:list[OrderLine]):self.id=idself._lines=linesself._events:list=[]defadd_line(self,line:OrderLine)->None:ifany(self.id=="shipped"forlinself._lines):raiseRuntimeErrorself._lines.append(line)self._events.append(("LineAdded",line))deftotal(self)->Money:returnsum((l.priceforlinself._lines),Money(Decimal(0),"USD"))classOrderRepo:# abstraction (port)defget(self,id:UUID)->Order:...defsave(self,order:Order)->None:...
classShippingPolicy(Protocol):defcost(self,order:Order)->Money:...classFlatRate:defcost(self,order):returnMoney(Decimal(5),"USD")classWeightBased:defcost(self,order):returnMoney(Decimal(order.weight()*0.5),"USD")# inject, not inheritclassCart:def__init__(self,shipping:ShippingPolicy):self._shipping=shipping
언제: aggregate boundary suggestion, code → DDD pattern mapping, layer violation detection.
언제 X: 매 over-engineering trivial CRUD — 매 LLM 의 DDD 의 over-prescribe 의 tendency, 의 push back.
❌ 안티패턴
Anemic domain: 매 getter/setter only data class + service 의 logic, 의 behavior 의 entity 의 push.
God aggregate: 매 한 aggregate 의 entire system, 의 split.
Leaky abstraction: 매 ORM model 의 domain 의 exposure, 의 separate.
Inheritance for reuse: 매 deep hierarchy, 의 composition.
Layer skipping: 매 controller → repository 직접, 의 application service 의 통과.
🧪 검증 / 중복
Verified (Evans "DDD" 2003, Vernon "Implementing DDD", Martin "Clean Architecture").