知识卡片

普通读书笔记卡 · 1971.o.1.b.4.e.1.b

值对象间避免双向关联

理解等级:中级

两个值对象都无概念身份时,让它们互相指向“同一个实例”缺少业务含义:替换成等值副本后,反向指针也未必还能指回原实例。因此应尽量消除值对象之间的双向关联,保留必要的单向关系。若模型确实需要持续识别反向所指的那个对象,应重新检查其中某个对象是否其实是实体。参见[[关联方向应按业务查询裁剪]]、[[值对象按描述而非身份理解]]。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第39章《原书第05章|Special Cases: When to Allow Mutability》(源文件:_epub-src/0321125215_ch05lev1sec3_split_002.html) - 结论依据:原文认为值对象间双向关联无法有意义地指回同一身份,要求尽量去除;如仍显得必要,应重审值对象分类是否隐藏了实体身份。 - 原始内容:Without identity, it is meaningless to say that an object points back to the same VALUE OBJECT that points to it. ... Try to completely eliminate bidirectional associations between VALUE OBJECTS . If in the end such associations seem necessary in your model, rethink the decision to declare the object a VALUE OBJECT in the first place.