EvansClassification
EvansClassification
In his excellent book Domain Driven Design, Eric Evans creates a classification of the different kinds of domain objects that you're likely to run into.
- Entity: Objects that have a distinct identity that runs through time and different representations. You also hear these called "reference objects".
- Value Object: Objects that matter only as the combination of their attributes. Two value objects with the same values for all their attributes are considered equal. I also describe value objectsin P of EAA.
- Service: A standalone operation within the context of your domain. A Service Object collects one or more services into an object. Typically you will have only one instance of each service object type within your execution context.
This classification is something that resonates功名 well with my experience of what you need in domain models. The trouble is that the trio三件套 are hard to define precisely, they are of the "I know them when I see them" category.
As such some examples may help. Entities are usually big things like Customer, Ship, Rental Agreement. Values are usually little things like Date, Money, Database Query. Services are usually accesses to external resources like Database Connection, Messaging Gateway, Repository, Product Factory.
One clear division between entities and values is that values override the equality method (and thus hash) while entities usually don't. This is because you usually don't want to have more than one object representing the same conceptual entity within your processing context, however you don't care about multiple "5.0" objects. Values may be primitives (in languages that make the distinction) or have special language support (as they do in .NET) but they don't have to. One important rule to follow is that value objects should be immutable (otherwise you get into all sorts of trouble with aliasing bugs). To change a value (such as my height) you don't change the height object, you replace it with a new one.
Service objects are often implemented by using global variables, class fields (monostates in Robert Martin's terminology) or singletons. Certainly they are usually singular单一的, in that you only have one of them, but how you do that is more varied. Usually the singularity is within a processing context - so one per thread in a multi-threaded environment. In any case you should ensure that your implementation mechanism is hidden from other domain objects so you can easily change it. Eric states in his book that services should be stateless, although we've talked about that and he no longer thinks that is necessary - although it's nice if you can do it.
One of the problems with this area is that this terminology, although evocative唤起的, gets terribly muddled up魂消 with other ideas.
Entity is often used to represent a database table or an object that corresponds to a database table.
Service has the whole Service Oriented Architecture thing going on, as well as service layers in application architecture.
So if I use these terms I have to make it clear I'm using them within the context of Domain Models and according to their meaning within Eric's book.
So be wary谨慎的 of assuming people are using these words like this - they are heavily overloaded. Sadly there's not much alternative.
EvansClassification的更多相关文章
随机推荐
- java详细剖析
1·类型加载主动初始化和被动初始化两种,通过访问静态变量或者给静态变量赋值都是可以使类初始化,如果有继承关系,所依赖的父类都会被动初始化. 2·如果在类的静态变量中添加final关键字,那这个变量就会 ...
- 2018-2019-2 20165336《网络攻防技术》Exp5 MSF基础应用
2018-2019-2 20165336<网络攻防技术>Exp5 MSF基础应用 一.攻击实例 主动攻击的实践 ms08_067(成功) payload/generic/shell_rev ...
- Elasticsearch学习笔记(十二)filter与query
一.keyword 字段和keyword数据类型 1.测试准备数据 POST /forum/article/_bulk { "index": { "_id" ...
- 模拟网络状况工具——clumsy
官网:http://jagt.github.io/clumsy/index.html 官网上的介绍已经很易懂了,所以本文只是直接翻译了官网内容. clumsy 能在 Windows 平台下人工造成不稳 ...
- linx下对文件权限设置
语法格式:chmod u+/-rwx,g+/-rwx,o+/-rwx filename 如:1. 给主人添加读权限,并减去执行权限:chmod u+r,u-x filename2. 给所有用户(主人. ...
- readlink 获取进程的绝对路径
readlink可以获取exe所在的路径(直接和进程关联);无法获得so的路径,so路径可以用dladdr,参考另一篇文章linux系统中有个符号链接:/proc/self/exe 它代表当前程序,所 ...
- ThinkPHP安全规范指引
流年 发布于 ThinkPHP官方博客: https://blog.thinkphp.cn/789333 本文主要和大家探讨一下ThinkPHP的安全注意事项,可以作为ThinkPHP建议的安全规范实 ...
- Ubuntu server LTS 16.04安装SSH以及连接问题
1.SSH安装 出现问题: 登录到Ubuntu服务器,执行以下命令: sudo apt-get install openssh-server 出现以下错误: 解决办法: 1)确保服务器能出外网,比如说 ...
- 获取Type的三种方式
using System;using UnityEngine; public class Type_Test : MonoBehaviour{ private void Awake() { ...
- SpringMVC常见面试题总结
1.什么是Spring MVC ?简单介绍下你对springMVC的理解? Spring MVC是一个基于MVC架构的用来简化web应用程序开发的应用开发框架,它是Spring的一个模块,无需中间整合 ...