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的更多相关文章

随机推荐

  1. 第二单元电梯调度作业 By Wazaki

    figure:first-child { margin-top: -20px; } #write ol, #write ul { position: relative; } img { max-wid ...

  2. [ionic3.x开发记录]参考ionic的float-label动效,写一个项目内通用的input组件,易扩展

    上图: module: import {NgModule} from "@angular/core"; import {CommonModule} from "@angu ...

  3. Linux常用命令之-删除文件

    在测试过程中,有时候会需要删除一些文件,例如日志文件过大等,这里汇总一些删除文件常用的命 已这个系统内的文件为例 删除文件(即这个文件被删除) 单个删除:rm -f + 文件名 eg:rm -f  2 ...

  4. ansible常用命令

    一.ansible常用命令 一.ansible命令的常用参数 ansible 默认提供了很多模块来供我们使用.在 Linux 中,我们可以通过 ansible-doc -l 命令查看到当前 ansib ...

  5. AIX 7.1 RAC 11.2.0.4.0升级至11.2.0.4.6(一个patch跑了3个小时)

    1.环境 DB:两节点RAC 11.2.0.4.0升级至11.2.0.4.6 OS:AIX 7.1(205G内存 16C) 2.节点1.节点2(未建库) 2.1.patch 20420937居然用了3 ...

  6. 白话skynet第三篇:通过队列解决多线程竞争资源

    今天遇到一个问题,在大厅服务中,如果一个请求使用到了一个公共的变量,如何保证其一致性? 虽然请求是挨个运行的,但是skynet.call会阻塞. "同一个 skynet 服务中的一条消息处理 ...

  7. python之单例模式

    #单例模式:有时需要写出高性能的类,那么会采用单例模式.通俗的解释就是类只创建一次实例,贯穿整个生命周期,实现了高性能. #1.模块化单例#所谓的模块化就是一个单独的.py文件来存储类,这样就是单例模 ...

  8. Java基础之流程控制

    一.顺序结构 顺序结构的程序语句只能被执行一次.如果您想要同样的操作执行多次,,就需要使用循环结构. if-else-if 语句 语法: if(条件){ 当条件为true时,执行大括号内的代码 }el ...

  9. egg.js异步请求数据

    之前已经简单的使用egg-init初始化项目,并创建控制器controller和服务service 在实际项目中, service主要负责数据的请求,并处理(http请求) controll主要负责获 ...

  10. 【原创】canvas裁剪上传图片异步提交

    <!DOCTYPE html> canvas裁剪图片,纯前端 裁剪文件 后台返回获取裁剪后的文件