知识卡片
服务无状态不等于无副作用
领域服务的“无状态”指任一调用方都能使用任一服务实例,结果不依赖该实例的个人历史;它仍可读取或改变外部可访问的信息,因此可能有副作用。判断服务是否成立,还要看操作是否确属领域概念、是否不自然地归属于实体或值对象,以及接口是否用领域模型的语言表达。参见[[领域服务不能掏空对象行为]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第05章|Services · 查看原书依据
A good SERVICE has three characteristics. The operation relates to a domain concept that is not a natural part of an ENTITY or VALUE OBJECT. The interface is defined in terms of other elements of the domain model. The operation is stateless. Statelessness here means that any client can use any instance of a particular SERVICE without regard to the instance's individual history.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第40章《原书第05章|Services》(源文件:_epub-src/0321125215_ch05lev1sec4.html)
- 结论依据:原文列出好服务的三个条件,并明确定义无状态只排除服务实例自身历史对行为的影响,不排除对全局信息的读写。
- 原始内容:A good SERVICE has three characteristics. The operation relates to a domain concept that is not a natural part of an ENTITY or VALUE OBJECT . The interface is defined in terms of other elements of the domain model. The operation is stateless. Statelessness here means that any client can use any instance of a particular SERVICE without regard to the instance's individual history. ... may even change that global information (that is, it may have side effects).