知识卡片
只把有业务意义的过程建入领域
判断过程是否应在领域模型中显化,关键是领域专家是否会谈论它。货物路由是原书案例中的业务过程,可由领域服务表达;若存在不同业务方法,可把算法或关键步骤建为可替换的策略。纯程序机制应隐藏在实现里,不因有流程就成为领域对象。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第09章|How to Model Less Obvious Kinds of Concepts · 查看原书依据
The key to distinguishing a process that ought to be made explicit from one that should be hidden is simple: Is this something the domain experts talk about, or is it just part of the mechanism of the computer program?
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第70章《How to Model Less Obvious Kinds of Concepts》,Processes as Domain Objects(源文件:_epub-src/0321125215_ch09lev1sec2_split_000.html)
- 结论依据:原文以专家是否谈论过程为判据,并区分 Service 与 Strategy 的表达。
- 原始内容:Right up front, let's agree that we do not want to make procedures a prominent aspect of our model. Objects are meant to encapsulate the procedures and let us think about their goals or intentions instead. What I am talking about here are processes that exist in the domain, which we have to represent in the model. [...] The first example in this chapter described a shipping system that routed cargo. This routing process was something with business meaning. A SERVICE is one way of expressing such a process explicitly, while still encapsulating the extremely complex algorithms. When there is more than one way to carry out a process, another approach is to make the algorithm itself, or some key part of it, an object in its own right. The choice between processes becomes a choice between these objects, each of which represents a different STRATEGY . [...] The key to distinguishing a process that ought to be made explicit from one that should be hidden is simple: Is this something the domain experts talk about, or is it just part of the mechanism of the computer program?