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. linux基础命令--groupmod 修改组定义

    描述 groupmod命令用于修改系统上的组定义. groupmod命令通过更改组数据库(the group database)里的相关条目来修改指定的组. 语法 groupmod [选项] GROU ...

  2. LG1484 种树

    题意 \(N\)个数,至多选\(k\)个,相邻两数不能同时选,问最大价值. 思路 一种假的思路:直接扔进对里面,每次都选最大的可以选的,再把两边和自己标记为不能选,一直贪心下去.是不是很有道理? 假在 ...

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

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

  4. maven插件--assembly

    之前maven项目中使用assembly插件单独打包项目依赖包,项目只有一个模块也就一个pom,配置这个插件,一切很顺利.但是现在的项目复杂了,有parent有child,多模块.按照之前的做法怎么也 ...

  5. MATLAB算术运算符和常用函数

    1 算术运算符 Matlab中的算术运算符按优先级由高到低为: (1) ^           幂 (2) *            乘      /            右除(正常除)       ...

  6. springboot的maven配置问题

    我是在idea中配置的中,mac,直接搜的网上最简单的教程,依赖包报错: project structure中引用路径报错 --> maven仓库的路径可能有问题 找不到springapplic ...

  7. Python练习:含参数的脚本示例

    首先准备一个example.csv文件,如下: 编写脚本test.py ,实现传入参数,读取example.csv文件,并将其保存为另一个文件, #  含参数的脚本,读取一个文件,并另保存一个文件im ...

  8. CentOS 7下 部署Redis-cluster集群

    redis集群是一个无中心的分布式redis存储架构,可以在多个节点之间进行数据共享,解决了redis高可用.可扩展等问题,redis集群提供了以下两个好处:1)将数据自动切分(split)到多个节点 ...

  9. redis 无序集合(set)函数

    sAdd 命令/方法/函数 Adds a value to the set value stored at key. If this value is already in the set, FALS ...

  10. Task3

    姓名:蔡典 学号:1425052044 班级:信管142 兴趣爱好:电影,美剧,游戏 个人编程能力:较弱,没自己写过代码 码云账号:18809188@qq.com 直接搜索码云然后进入官网输入基本信息 ...