Domain Modeling
通过识别核心业务概念构建领域模型,是 DDD 的基础。
1// 实体:NFT2type NFT struct {3 ID NFTID // 唯一标识4 TokenID *big.Int 5 Contract common.Address 6 Owner common.Address 7 Metadata NFTMetadata // 值对象8 CreatedAt time.Time9}10 11// 值对象:NFT 元数据(不可变)12type NFTMetadata struct {13 Name string14 Description string15 Image string16 Attributes []Attribute17}18 19// 聚合根:订单20type Order struct {21 ID OrderID22 NFT *NFT // 关联实体23 Seller common.Address24 Buyer *common.Address25 Price Price // 值对象26 Status OrderStatus27 Events []DomainEvent // 领域事件28}29 30// 值对象:价格31type Price struct {32 Amount *big.Int33 Currency common.Address // 代币合约地址34}35 36// 领域服务:交易撮合37type TradeMatchingService interface {38 Match(order *Order, buyer common.Address) (*Trade, error)39}