知识卡片
限定条件使关联更精确
给关联加限定条件,可把笼统的“一对多”变成在指定条件下的“一对一”。原书例子:国家有多位历任总统,通常指定时期后只查对应的一位;经纪账户可按股票代码查一项投资,前提是业务规则确实规定每只股票仅有一项投资。限定条件既显露规则,也使模型更精确、实现更易维护;内战等特殊时期或需要追踪多个买入批次时,前提须重新核对。参见[[关联方向应按业务查询裁剪]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第05章|Associations · 查看原书依据
This wouldn't be true of all business situations (for example, if the lots need to be tracked), but whatever the particular rules, as constraints on associations are discovered they should be included in the model and implementation.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第35章《原书第05章|Associations》(源文件:_epub-src/0321125215_ch05lev1sec1.html;图5.2、5.4:05fig02.gif、05fig04.gif)
- 结论依据:原文以时期限定总统、股票代码限定账户投资说明多重性收束,并明确若需追踪批次,账户每只股票一项投资的假设并非普遍成立。
- 原始内容:Very often, deeper understanding leads to a "qualified" relationship. Looking deeper into presidents, we realize that (except in a civil war, perhaps) a country has only one president at a time. This qualifier reduces the multiplicity to one-to-one, and explicitly embeds an important rule into the model. [...] Let's refine the model by qualifying the association between Brokerage Account and Investment , reducing its multiplicity. This says there can be only one investment per stock. Figure 5.4. This wouldn't be true of all business situations (for example, if the lots need to be tracked), but whatever the particular rules, as constraints on associations are discovered they should be included in the model and implementation. They make the model more precise and the implementation easier to maintain. (`[...]` 标明非连续省略;`Investment ,` 为空格保留原 EPUB 标签抽取形式。)