Aggregates and aggregation roots confusion

旧时模样 提交于 2021-01-27 14:16:15

问题


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

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.

enter image description here

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

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..

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. This tends to confuses me as i have an aggregate root(Airplane) inside another aggregate(Flight Aggregate).
  2. Since the aggregate root is consider to be the "CORE" entity which without it the other entities inside it will not make any sense without it, i am thinking about Company. And i conclude that company makes sense without the airplane.

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 principles say that any entities inside the aggregate may only be loaded from the root itself. So here is the confusion.


回答1:


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

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).

[Edit]

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...




回答2:


An aggregate is a group of entities (objects with identity) and maybe value objects (objects without identity, immutable). There is exactly one entity in an aggregate that is the aggregate root. You can easily identify it by checking if the other objects in the aggregate depend on it, for example, if you delete an object of the aggregate root type, the remaining objects don't make sense anymore (in database terms, you'd cascade delete the dependent objects).

The aggregate root is the sole object in the aggregate that gives access to the other types in the aggregate, hence you'll have one repository per aggregate and it returns instances of aggregate root type.



来源:https://stackoverflow.com/questions/20601937/aggregates-and-aggregation-roots-confusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!