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的更多相关文章
随机推荐
- go 学习第一个hello world 遇到的问题
mac:Go安装和配置+GoLand安装和使用之完整教程 https://blog.csdn.net/zxy_666/article/details/80182688 前言作为一个go语言程序员,觉得 ...
- React之ref
作为响应式开发框架React,我们知道他是数据驱动的,但有时候避免不了还是得动用到DOM操作,这个时候我们就可以用到ref:用法如下: 然后这样做有个弊端,当一个 ul 下面的 li 是动态添加的时候 ...
- zabbix自定义监控项、添加图形、设置触发器、远程执行命令
监控项是在zabbix中手机数据的基础,没有监控项就没有数据,系统自带模板带有大量默认item,自定义item可以定义在模板中,在应用模板即可使用对应item:也可直接在host中定义 目标:自定义监 ...
- Spring+Mybatis 复杂的分组查询
1.需要的结果数据格式为 { "responseCode": "0000", "responseMsg": null, "data ...
- API网关学习及介绍
一.什么是API网关 API网关是一个服务器,是系统的后端统一入口.首先,它会提供最基本的路由服务,将调用转发到上游服务.其次,作为一个入口,它还可以进行认证,鉴权,限流等操作,对上游服务保护.所以说 ...
- .NET[C#]中NullReferenceException(未将对象引用到实例)是什么问题?如何修复处理?(转)
.NET[C#]中NullReferenceException(未将对象引用到实例)是什么问题?如何修复处理? 后端开发 作者: Rector 1973 阅读 0 评论 0 收藏 收藏本文 ...
- SetFileAttributes 设置属性
#include <Windows.h> #include <tchar.h> int WINAPI _tWinMain(HINSTANCE hInstance, HINSTA ...
- Canvas Snippets
========================================== Example: 1. To revel "fillStyle" property, type ...
- JFinal框架
FJinal过滤器(tomcat) 创建java类继承JFinalConfig 会实现六个方法(有一个是拦截器的方法好像是,那个我好像看的跟struts2一样但是又没看懂暂时不写) Controlle ...
- NN元数据工作机制
HDFS的实现思路:1.HDFS通过分布式集群来存储文件,为客户端提供便捷的访问方式2.文件存储到HDFS集群去的时候,被切分为block3.HDFS存放在若干datanode节点 上4.HDFS文件 ...