知识卡片

普通读书笔记卡 · 1971.o.1.b.4.d.1.c.1.b.4.a

值对象复制共享看通信成本

理解等级:高级

值对象没有业务身份,可按环境选择复制或共享实例。共享大量相同的房屋插座对象可节省对象数;但在分布式系统里,传一次副本后可在接收端独立使用,远程共享引用却可能每次交互都要回传消息。共享更适合节省空间很关键、通信开销低且对象严格不可变的场景。原书插座数量只是说明性例子,不是实测性能结论。参见[[不可变使值对象安全共享]]。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第38章《原书第05章|Is "Address" a V ALUE O BJECT ? Who's Asking?》(源文件:_epub-src/0321125215_ch05lev1sec3_split_001.html) - 结论依据:原文对比复制造成对象数量增加与跨机器共享引用造成反复通信,并列出共享适用的三项条件;插座复用是其说明性假设。 - 原始内容:If each electrical outlet is a separate VALUE OBJECT , there might be a hundred of them in a single version of a single house plan. But if all outlets are considered interchangeable, we could share just one instance of an outlet and point to it a hundred times (an example of FLYWEIGHT [ Gamma et al. 1995 ]). [...] The economy of copying versus sharing depends on the implementation environment. Although copies may clog the system with huge numbers of objects, sharing can slow down a distributed system. When a copy is passed between two machines, a single message is sent and the copy lives independently on the receiving machine. But if a single instance is being shared, only a reference is passed, requiring a message back to the object for each interaction. Sharing is best restricted to those cases in which it is most valuable and least troublesome: When saving space or object count in the database is critical When communication overhead is low (such as in a centralized server) When the shared object is strictly immutable (`[...]` 标明非连续省略;末尾三项是原 EPUB 无句号列表,按抽取顺序连接转录。)