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. @ResponseBody ResponseEntity

    1.产生疑问 我们知道,如果在 Controller 的某个方法上加上 @ResponseBody 注解,那么你就能拿到 json 数据. 如果你只是知道这么用,那么你应该知道 ResponseBod ...

  2. 2018(5)软件架构设计,架构风格,REST

    2018上半年系统分析师试题五 阅读以下关于Web应用设计开发的描述,在答题纸上回答问题1至问题3. [说明] 某公司拟开发一个自由,可定制性强.用户界面友好的在线调查系统,以获取员工在课程学习.对公 ...

  3. opencart3产品页调用upc/数量等信息

    opencart3产品页默认只调用标题.价格.型号等几个数据,如果想要调用更多的参数要如何操作呢?跟着ytkah一起来看看吧.首先打开/catalog/model/catalog/product.ph ...

  4. 数据结构 - 表插入排序 具体解释 及 代码(C++)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012515223/article/details/24323125 表插入排序 具体解释 及 代码 ...

  5. gitlab自动备份和定时删除

    GitLab数据手动备份1.GitLab默认备份目录为/var/opt/gitlab/backups,可以修改/etc/gitlab/gitlab.rb里面的默认存放备份文件目录,这里使用默认备份目录 ...

  6. Prometheus部署监控容器

    Prometheus架构描述 Prometheus 是一个非常优秀的监控工具.准确的说,应该是监控方案.Prometheus 提供了监控数据搜集.存储.处理.可视化和告警一套完整的解决方案 Prome ...

  7. js 获取鼠标的手势方向角度

    需要获取鼠标的移动角度 1.mousedown 确定起始点 2.mousemove 确立相关点 3.先计算两点的斜率,然后根据三角函数和反三角函数.转换为角度 <!DOCTYPE html> ...

  8. python小程序--Two

    一.程序需求 1.启动程序后,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 4.可随时退出,退出时,打印已购买商品和 ...

  9. xlua build时 报错处理

    error trpe 'UnityEngine.Lighr' does not contain a definiton for 'sgadowRadius' and no extension meth ...

  10. python爬虫程序打包为exe程序并在控制台下运行

    上一篇文章实现了爬取任意两个用户共同想读的图书的python程序.现在此程序打包为exe程序. 使用pyinstaller实现此功能.在pyinstaller官网下载http://www.pyinst ...