1领域模型
领域模型是对业务领域的抽象,包含实体、值对象、聚合等概念。
核心概念: - **实体 (Entity)**:有唯一标识的对象 - **值对象 (Value Object)**:无标识,不可变 - **聚合 (Aggregate)**:一组相关对象的集合 - **聚合根 (Aggregate Root)**:聚合的入口点
go
1// 实体2type Order struct {3 ID OrderID4 Customer CustomerID5 Items []OrderItem6 Status OrderStatus7 CreatedAt time.Time8}9 10// 值对象11type Money struct {12 Amount decimal.Decimal13 Currency string14}15 16func (m Money) Add(other Money) Money {17 return Money{18 Amount: m.Amount.Add(other.Amount),19 Currency: m.Currency,20 }21}