文档章节

Are Repositories Domain Model Objects?

猪刚烈
 猪刚烈
发布于 2014/10/12 11:40
字数 392
阅读 10
收藏 0

 I focus on DDD for a long time,and I am working on an open source project with DDD now.Recently,I am thinking about the repository.I reffered to DDD Sample Project,I noticed that: repositories are placed in "domian.model" package. I deliberated repository again, I think we should not regard it as a part of domain model! The reasons as below:
    1.From pure domain view,there is no "repository" conception.It looks like a "programming-specific"  mechanism more .For example: in the "domain.model.cargo" package of DDDSample,The cargo,delivery or itinerary,they are all looks good,because they are "real role" in domain model,howerver,the CargoRepository looks weird,  they may make domain experts confused!
    2.I also admit that: Repository make sense for domain model.we indeed need a role which represents a collection of domain objects and provides CRUD service.however,no matter how to emphasis this role's "domain property",it still have to get involved in data acess logic!If we regard this role as a part of domain medel,the data access logic may "pollute" domain model!For example: in DDDSample,designers place repository interface in domain.model package,however,designers themself are also aware of their hibernate implement classes should not be placed in "domain.model",so,they placed them in infrastructure package.Why interface and its implement class are so different that make them so estranged?They shouldn't be such relationship!The source of problem is like what I mentioned:Even though it is only an inerface in domain model,repositories have to deal with data access logic,this is their inherent responsbility!Interface can not conceal it.
   So,I think it is not suitable to place repositories in domain model.We all know:For creating a clean domain model,domain model object should not depend on any service or repository.Actually,repositories are only invoked by service when they want to persist aggregation root.
So,I think we should regard repositories as a special kind of domain object,It only works on aggregate roots,and invoked by service when aggregate roots need persistence.And finally,I think it is better if we place repositories in such package:"domain.repository" that stand "domain.model" and "domain.service" side by side!
Be careful:The package name is "domain.repository" not "dataaccess.repository" or "persistence.repository"!Repository is a sepical domain object like service!This is my opinion!

本文转载自:http://blog.csdn.net/bluishglc/article/details/4867268

共有 人打赏支持
猪刚烈
粉丝 22
博文 708
码字总数 110
作品 1
海淀
程序员
私信 提问
DDD: Part I (Introduction)

The first time I heard about DDD (Domain Driven Design, not Deadline Driven Design, for sure), I was still working as a Senior Java Developer for Hewlett-Packard at its Developm......

M Yauri Maulana at-Tamimi
2017/12/14
0
0
centos5.6 gitolite-admin 问题,求助

git.exe push -v --progress "origin" master:master Pushing to git@118.145.14.172:repositories/gitolite-admin Counting objects: 15, done. Compressing objects: 100% (10/10) Writing......

橙汁儿
2012/01/06
737
0
JSON反序列化库--Upida

Upida 是一个轻量级的库,主要的目的是反序列化 JSON 数据到域对象。实现了: Assigns back-references to domain objects. Copies data from MVC model to persistent objects (with no cus...

红薯
2014/03/04
286
0
配置koala创建项目之后一直报错

@Koala_考拉 你好,想跟你请教个问题:请问eclipse配置好koala后,项目一直都是报错的,要怎么解决,错误信息都是说找不到jar包,例如: Failed to read artifact descriptor for org.dayat...

BertramTan
2017/06/23
276
0
XenAPI

XenAPI方式: #!/usr/bin/python from xen.xm.XenAPI import Session session=Session('httpu:///var/run/xend/xen-api.sock') try: session.loginwithpassword('', '') xenapi=session.xena......

文艺小青年
2017/05/11
0
0

没有更多内容

加载失败,请刷新页面

加载更多

eslint rules 规则

'rules': { "comma-dangle": ["error", "never"], //是否允许对象中出现结尾逗号 "no-cond-assign": 2, //条件语句的条件中不允许出现赋值运算符 "no-console": 2, //不允许出现console语句 ...

agenyun
16分钟前
1
0
类型判断时instanceof和equals的不同用法

接口设计时为了避免序列化的麻烦,将接口定义为参数为map<String,String>类型的接口,但是现在调用时需要转换当前的实体Bean为Map,接口接收方再把Map转换为另一个Bean实体。过程中的需要对类...

wangtx
22分钟前
1
0
vue 组件间传值(个人精编)

1.父组件向子组件传值 1⃣️.子组件标签绑定需要传递的参数名2⃣️.子组件页面使用props 接收参数 2.子组件向父组件传值  1⃣️.子组件使用$emit来触发一个自定义事件,并传递一个参...

MrBoyce
33分钟前
1
0
(荷兰)彼得·冯·门施著:博物馆学研究的目的

博物馆学研究的目的 (荷)彼得·冯·门施 尽管诸多关于博物馆学认知目的的不同看法可以被归纳为数个主要群体,但没有一个群体可以被称为“学派”。一般来说,学派是由于博物馆学研究目的的不...

乔老哥
42分钟前
2
0
Vue slot的用法

之前看官方文档,由于自己理解的偏差,不知道slot是干嘛的,看到小标题,使用Slot分发内容,就以为 是要往下派发内容。然后就没有理解插槽的概念。其实说白了,使用slot就是先圈一块地,将来...

peakedness丶
54分钟前
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部