聚合和聚合根源混淆 [英] Aggregates and aggregation roots confusion

查看:104
本文介绍了聚合和聚合根源混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经分配了一个非常简单的项目作为考试,并且我有使用域驱动设计进行开发的想法.

i've been assigned a quite simple project as an exam and i had the idea to develop it using the Domain Driven Design.

许多人可能会说应用程序是如此简单,以至于使用存储库和UoW只是浪费时间,您也许是正确的,但我认为这是学习更多内容的机会.

Many of you might say that the application is so simple that going with repositories and UoW is just a waste of time, and you probably be correct but i think of it as an opportunity to learn something more.

该应用程序是一个机票"系统,从下图可以很容易地猜到它的功能.

The application is a "Flight tickets" system and from the following image you could probably well guess it's functionality.

问题是我不确定我是否正确地分离了聚集体及其根.

The thing is that i am not sure if i am correctly seperating the aggregates and their roots.

我介绍了数据模型,以便任何人都可以轻松发现整个功能.

I presented the data model so anyone can spot the whole functionality easily.

从员工的角度来看,"Rad"表示的飞行封装了整个功能,并且是总根.

The thing is that from an employe perspective the flight as "Rad" said encapsulates the whole functionality and is the aggregate root.

但是,从管理员的角度来看,航班并不是他的事.他只想更新或添加新的飞机公司等.

However from an admin perspective, flights are none his bussiness. He just want to update or add new planes-companies, etc..

然后有一个新的聚合根,这是飞机,它将飞机座位(实体),seatType(值对象)和公司(实体)封装为新的聚合.

So then there is a new aggregate root which is the Airplane which encapsulates the Airplane seats(Entity), the seatType(value object) and the company(Entity) as a new aggregate.

  1. 这使我感到困惑,因为我在另一个聚合(飞行聚合)中有一个聚合根(飞机).
  2. 由于聚合根被认为是核心"实体,如果没有它,则内部的其他实体将没有任何意义,因此我正在考虑公司.我得出的结论是,没有飞机,公司就很有意义.

为进一步解释,我想到了管理员只想插入一个新公司,或先加载公司然后加载飞机的情况.

To explain more i think of the scenario where the admin want to just insert a new Company, or want to first load a company and then its airplanes.

DDD原理说聚合内的任何实体只能从根本身加载.这就是困惑.

DDD principles say that any entities inside the aggregate may only be loaded from the root itself. So here is the confusion.

推荐答案

嗯,这里的Aggregate和Aggregate根在哪里?这只是数据模型,而不是域模型.

Mmm, where is the Aggregate and Aggregate roots here ? This is only Data Model... Not Domain Model.

聚合是一组聚集在一起的项目(域对象),聚合根是实体根...(如果您认为Flight Aggregate封装了Seats,Location……聚合根应该是Flight实体)

Aggregate is a cluster of items (Domain Object) that are gathered together, and Aggregate Root are the entity root... (If you consider the Flight Aggregate encapsulates Seats, Location... The Aggregate Root should be Flight entity).

您必须忽略持久性.在您的应用程序中,您可以在域中依赖它的多个聚合,也许Flight是一个聚合,而Company则是另一个;),不要混淆实体和Aggregate ...

You have to ignore the persistent. In your app you can have many aggregate it depends in your Domain, maybe Flight is an Aggregate and Company another one ;), don't confuse entity and Aggregate...

这篇关于聚合和聚合根源混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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