知识卡片
复制值对象改善数据局部性
值对象无需追踪实例身份,因此可在不改变业务含义的前提下复制。原书的数据库调优例子把同一值复制到使用它的实体附近,减少跨存储位置读取;关系表中也可把值放入实体表而非另建关联表。分布式调用传副本,可避免之后反复访问远端共享实例。代价是存储重复和维护复杂度,只有访问时间更关键时才适合这种反规范化。参见[[值对象复制共享看通信成本]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第05章|Special Cases: When to Allow Mutability · 查看原书依据
By making a copy, rather than sharing a reference to the same instance, a VALUE OBJECT that is acting as an attribute of many ENTITIES can be stored on the same page as each ENTITY that uses it.
参考来源
- 位置:《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)
- 结论依据:原文以数据库物理聚集解释复制值对象可把数据放到使用者附近,并提到关系表内联值与跨服务器传副本的技术取舍,明确反规范化用于访问时间更重要的场景。
- 原始内容:By making a copy, rather than sharing a reference to the same instance, a VALUE OBJECT that is acting as an attribute of many ENTITIES can be stored on the same page as each ENTITY that uses it. ... This technique of storing multiple copies of the same data is called denormalization and is often used when access time is more critical than storage space or simplicity of maintenance.