领域驱动设计--第三天

Entities and Value Objects

Entities and Value Objects (VO) form the core building blocks of Domain Driven applications. Why has it taken this long to get to something so fundamental? Back in the good old days we used to have things called business objects, these were classes that held some data, had some methods, and we threw into a database.

DDD has refined this concept a little, by splitting the idea of these business objects into two distinct types,Entities and Value Objects

Entities

“this is my Entity, there are many like it, but this one is mine”


Whichever way you choose to represent it, an Entity is defined by having an Identity.


Value Objects

The key defining characteristic of a Value Objects is that it has no Identity. Ok, perhaps a little simplistic, but the intention of a Value Object is to represent something by it’s attributes only. Two VOs may have identical attributes, in which case they are identical. They don’t however have any value other than by virtue of their attributes.

Another aspect common to  VOs  is that they should probably be immutable, once created they cannot be changed or altered. You can create a new one, and as they have no identity, that is just the same as changing another one.

Examples of common Value Objects: Money, Address, ProductCode

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值