知识卡片
创建货物时同步建立交付历史
原书货运模型里 Cargo 与 Delivery History 相互引用,单独造出其中一个会留下不完整关系。因历史在 Cargo 聚合内,可由根的构造器或工厂在创建货物时同步生成空历史,并让历史指回该 Cargo;客户角色映射也初始化。原书给出的新货物暂为空 Delivery Specification,这是该场景的初始状态,不是任意货物永久可无交付目标。参见[[工厂一次产出有效聚合]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第07章|Object Creation · 查看原书依据
The two-way association between Cargo and Delivery History means that neither Cargo nor Delivery History is complete without pointing to its counterpart, so they must be created together.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第56章《原书第07章|Object Creation》(源文件:_epub-src/0321125215_ch07lev1sec8.html;Cargo 构造器示例)
- 结论依据:原文指出货物与历史的双向关联必须一起创建,允许聚合根构造器或工厂生成内部历史,并展示历史构造器接收 Cargo。
- 原始内容:The two-way association between Cargo and Delivery History means that neither Cargo nor Delivery History is complete without pointing to its counterpart, so they must be created together. ... The result is a new Cargo with a new Delivery History that points back to the Cargo .