返回主题:资源库与查询

此卡片不在当前主题的阅读序列中,可返回主题继续阅读。

知识卡片

结构图卡 · 1971.o.1.b.4.d.1.c.4

对象生命周期由三类模式协作

理解等级:中级

长寿命的领域对象可能在活跃、存储、重建、归档之间转换,还须在状态变化中维持业务不变量(始终必须成立的规则)。三类模式各有职责:聚合划出维护不变量的边界;工厂封装复杂对象的创建和重建;仓储封装持久对象的查找与取回。简单、短暂的对象无需为此增加复杂结构。下图按原书图6.1呈现生命周期;三类模式的具体规则留待后续小节。

结构图:

stateDiagram-v2
    [*] --> 活跃: 创建
    活跃 --> 活跃: 修改
    活跃 --> 存储表示: 存储
    存储表示 --> 活跃: 取回与重建
    活跃 --> 归档表示: 归档
    活跃 --> [*]: 删除
    归档表示 --> [*]: 删除
这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第43章《Chapter Six. The Life Cycle of a Domain Object》(源文件:_epub-src/0321125215_ch06.html;图6.1) - 结论依据:原文及图6.1展示对象从创建、活跃、持久化到归档或删除的转换,并概述聚合、不变量、工厂与仓储在生命周期中的职责;没有在本节给出其详细实现规则。 - 原始内容:This chapter will address these issues through three patterns. First, AGGREGATES tighten up the model itself by defining clear ownership and boundaries, avoiding a chaotic, tangled web of objects. This pattern is crucial to maintaining integrity in all phases of the life cycle. Next, the focus turns to the beginning of the life cycle, using FACTORIES to create and reconstitute complex objects and AGGREGATES , keeping their internal structure encapsulated. Finally, REPOSITORIES address the middle and end of the life cycle, providing the means of finding and retrieving persistent objects while encapsulating the immense infrastructure involved. [...] AGGREGATES mark off the scope within which invariants have to be maintained at every stage of the life cycle. F ACTORIES and REPOSITORIES operate on AGGREGATES , encapsulating the complexity of specific life cycle transitions. (`[...]` 标明非连续省略;`F ACTORIES` 是原 EPUB 首字母排版拆分。)