知识卡片
别给值对象强加身份
若业务只关心对象描述的值,仍给每个实例分配唯一 ID,会迫使系统保存、传播和核对本来不需要的身份。这样既增加存储与分布式追踪工作,也可能限制性能优化,并误导模型把值对象当作实体处理。身份追踪应留给确实需要区分“同一个”的实体;不要因框架会自动生成 ID,就把技术标识当成业务身份。参见[[实体身份跨表示延续]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第05章|Value Objects · 查看原书依据
Tracking the identity of ENTITIES is essential, but attaching identity to other objects can hurt system performance, add analytical work, and muddle the model by making all objects look the same.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第37章《原书第05章|Value Objects》(源文件:_epub-src/0321125215_ch05lev1sec3_split_000.html)
- 结论依据:原文指出给每个对象赋 ID 会增加追踪与分析负担、排除一些性能优化,并使所有对象在模型中被迫采取同一种身份形态。
- 原始内容:Tracking the identity of ENTITIES is essential, but attaching identity to other objects can hurt system performance, add analytical work, and muddle the model by making all objects look the same.