← 返回刚才阅读的位置

知识卡片

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

策略对象表达领域政策

理解等级:中级

若业务过程有多种合法做法,可把可变的规则或过程抽成独立 Strategy/Policy 对象,让主体过程保留稳定职责。多个策略对象分别表达不同选择,代码中也可替换实现。

只有当这项差异本身有业务含义(如路线按时间或成本权衡)时,它才不只是技术层的算法替换,而成为领域模型中的政策概念。应给策略取能说明业务规则的名称,并核对选择权属于谁。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第12章|Strategy (A.K.A.Policy) · 查看原书依据

      Factor the varying part of a process into a separate "strategy" object in the model. Factor apart a rule and the behavior it governs. Implement the rule or substitutable process following the STRATEGY design pattern. Multiple versions of the strategy object represent different ways the process can be done.

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第88章《Strategy (A.K.A.Policy)》(源文件:_epub-src/0321125215_ch12lev1sec1.html;单元01) - 结论依据:原文要求把过程中的可变部分抽为模型内策略对象,并区分技术算法可替换性与领域政策概念。 - 原始内容:Factor the varying part of a process into a separate "strategy" object in the model. Factor apart a rule and the behavior it governs. Implement the rule or substitutable process following the STRATEGY design pattern. Multiple versions of the strategy object represent different ways the process can be done.