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. RS232通信(Android)

    一. 添加依赖dependencies { implementation 'com.github.kongqw:AndroidSerialPort:1.0.1'} 二. 使用方法 package co ...

  2. Scala中foldLeft的总结

    源码分析 def seq: TraversableOnce[A] 上面两段代码是scala.collection.TraversableOnce特质的foldLeft方法源代码,实现了Traversa ...

  3. 2018-2019-2 20175211 实验二《Java面向对象程序设计》实验报告

    目录 代码托管 一.单元测试 (1)三种代码 二.TDD(Test Driven Development,测试驱动开发) 三.面对对象三要素 四.练习 五.问题及解决 六.PSP 代码托管 一.单元测 ...

  4. java 写一个JSON解析的工具类

    上面是一个标准的json的响应内容截图,第一个红圈”per_page”是一个json对象,我们可以根据”per_page”来找到对应值是3,而第二个红圈“data”是一个JSON数组,而不是对象,不能 ...

  5. FB面经Prepare: Bipartite a graph

    input friends relations{{1,2}, {2,3}, {3,4}} 把人分成两拨,每拨人互相不认识, 所以应该是group1{1,3}, group2{2,4} 这道题应该是ho ...

  6. windows----------windows10如何固定局域网ip

    1. 2. 3. 4. 5.

  7. linux----------启动network的时候报错Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.

    1.仔细阅读上面的话,意思是让你执行  journalctl -xe 查看更详细的日志. 2.我当时导致这个情况的原因是因为,虚拟机加载的文件被我换了位置,导致没加载到最原始的centos包.关闭虚拟 ...

  8. windows server 2008 R2服务器无法通过ShellClass获取mp3音乐时长

    我们先看一段代码,获取mp3播放时长: #region GetMediaDetailInfo 获取媒体文件属性信息 /// <summary> /// 获取媒体文件属性信息 /// < ...

  9. Linux内核开发进阶书籍推荐(不适合初学者)

    Linux内核开发进阶书籍推荐(不适合初学者) 很早之前就想写一篇文章总结一下Linux Kernel开发的相关资料,项目的原因,再加上家里的一些事情,一直没能找到闲暇,今天终于有些时间,希望可以完成 ...

  10. openGL实现图形学扫描线种子填充算法

    title: "openGL实现图形学扫描线种子填充算法" date: 2018-06-11T19:41:30+08:00 tags: ["图形学"] cate ...