知识卡片
领域服务承载独立动作
有些领域概念更像“执行一项动作”,而不是一个需要身份或承载状态的对象。若操作难以自然归属某个实体或值对象,可把它表达为供调用方请求的领域服务,避免为了保持对象形式而硬塞职责。这里的“服务”指领域模型中的行为表达;技术层也有服务,不能只凭名称混为一谈。参见[[实体与值对象按身份区分]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter Five. A Model Expressed in Software · 查看原书依据
Then there are those aspects of the domain that are more clearly expressed as actions or operations, rather than as objects. Although it is a slight departure from object-oriented modeling tradition, it is often best to express these as SERVICES, rather than forcing responsibility for an operation onto some ENTITY or VALUE OBJECT. A SERVICE is something that is done for a client on request. In the technical layers of the software, there are many SERVICES. They emerge in the domain also, when some activity is modeled that corresponds to something the software must do, but does not correspond with state.