在域驱动器设计中,您使用什么方法来标识聚合根? [英] What method do you use to identify the Aggregate Roots in Domain Drive Design?

查看:108
本文介绍了在域驱动器设计中,您使用什么方法来标识聚合根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将域驱动设计应用于项目时,如何识别集合根?

When applying Domain Driven Design to a project, how do you identify the Aggregate Roots?

例如,在一个标准的电子商务网站中,您可能会说订单是一个,用户是另一个。
但是,如果您的用户属于公司怎么办?

For example, in a standard E-Commerce website, you might say that the Order is one, and the User is the other. But what if your Users belong to a Company? Does that make your Company the aggregate root?

我很想听听人们计算汇总根的方法,以及如何识别选择不佳的汇总根。

I'm interested in hearing people's approaches to working out the Aggregate roots, and how to identify poorly chosen aggregate roots.

推荐答案

识别聚合根的一种好方法是使用删除测试。在您的域中,如果您删除根,那么根将删除什么?这样,您可以识别域对象的所有权,这是聚合的一个特征。

One good way of identifying the aggregate root is to use the "delete" test. In your domain if you delete the root, what is deleted with it? This way you can identify domain object ownership, which is a trait of Aggregates.

此外,聚合会创建一致性边界,因此您的根目录应隐藏其余的聚合元素并检查它们的一致性和应保持的不变性。聚合内的对象仅保留对根的引用(而不是对彼此的引用)。因此,如果您在域模型中找到类似的东西,则可能表明您具有聚合根。

Also Aggregates create consistency boundaries, so your root, should "hide" aggregated elements from the rest of the object graph and also check their consistency and invariants which should hold. Object inside the Aggregate hold references only to the root (not each other). So if you find someting like this in your domain model, it might suggest you have an Aggregate root.

这篇关于在域驱动器设计中,您使用什么方法来标识聚合根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆