知识卡片
循环关联的实现取决于查询频率
原书模型有 Cargo→Delivery History→Handling Event→Cargo 的概念环;实现时双向保存同一关系,新增事件需维护同步。首版可让历史持有事件列表,但作者认为它简单而脆弱;若历史查询少,可改按 Cargo 键查事件,减少同步与写入负担;若查询很频繁,维护直接引用可能更合适。模型关系仍可保持,存储方式由实际访问模式决定。图7.2展示此环。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第07章|Designing Associations in the Shipping Domain · 查看原书依据
If this query is very frequent, then it is better to go ahead and maintain the direct pointer. These design trade-offs balance simplicity of implementation against performance.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第52章《原书第07章|Designing Associations in the Shipping Domain》(源文件:_epub-src/0321125215_ch07lev1sec4.html;图7.2)
- 结论依据:原文指出环形引用维护难,并比较事件列表、按货物键数据库查询及高频查询时直接引用的取舍。
- 原始内容:Circular references logically exist in many domains and are sometimes necessary in design as well, but they are tricky to maintain. ... If this query is very frequent, then it is better to go ahead and maintain the direct pointer. These design trade-offs balance simplicity of implementation against performance.