Aggregates and aggregation roots confusion

307 views Asked by At

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.

2

There are 2 answers

1
rad On BEST ANSWER

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

0
Thorsten Westheider On

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.