Domain Driven Development相关概念

时间:2023-03-01 21:47:56

Entity 与 Value Object
1,Entity有唯一的身份标识,是可变的对象。Value Object是immutable,创建了就不能改变。
2,Value Object可以在多个领域之间重用,Entity是对实际领域的抽象。
3,Entity包含完整信息,Value Object只包含部分信息

怎么识别聚合对象
聚合对象是一组关系非常近的Entity或value Object的集合,通过聚合在这些对象周围开成固定的边界。聚合根是外部引用的入口。

Evans关于聚合的两条推荐准则:

1)聚合不要设计的过大,过大的聚合很难确保不变性,从而很难确保数据的强一致性;
2)聚合与聚合之间不要通过引用的方式来关联,而应该通过ID关联,通过ID关联也同样能表示聚合之间的关系,
    并且具有更好的性能和可伸缩性,聚合根之间通过ID关联的好处是:不会因为Load一个聚合根而把其他关联的聚合根一起Load出来,这样也避免了Load一个聚合根会把整个数据库Load出来的风险; 
    另外,对ORM的要求也很低,不需要ORM支持LazyLoad;

聚合根与聚合根之间的关系不像聚合内的Entity之间这么强烈内聚,它们之间仅仅是某种比较弱的关联关系,每个聚合根都有其独立的生命周期;

如customer和order都是聚合对象,要customer的所有订单,应该是customer.getOrderIDList(),而不是customer.getOrders()

相关链接

https://github.com/yuezhongxin/CNBlogs.Apply.Sample --cnblogs实例

http://www.eventuallyinconsistent.com/2012/01/changing-mindset-part-1-4-classic.html
http://www.jdon.com/ddd.html
https://martinfowler.com/tags/domain%20driven%20design.html
http://www.ituring.com.cn/article/25
http://colobu.com/2015/05/19/CQRS-and-Event-sourcing/
http://www.cnblogs.com/netfocus/p/4150084.html
https://github.com/gregoryyoung/m-r CQRS示例
http://www.cnblogs.com/netfocus/archive/2011/10/10/2204949.html
https://www.zhihu.com/topic/19826540/hot
https://www.codeproject.com/articles/339725/domain-driven-design-clear-your-concepts-before-yo?display=print
https://blog.csdn.net/chunlongyu/article/details/71302243
http://www.cnblogs.com/wangiqngpei557/p/3908337.html