Problem defining DDD Aggregates and Entities

48 Views Asked by At

I am working in a project that involves lots of requirements, conditions and entities so we are thinking about refactoring into Domain Driven Design architecture but we are struggling with the Entity and Aggregate definitions.

We have the following entities: Area (id, name) Line(id, fluid, diameter...) Pipe(id, tag, train, ...)

The problem here is that the Pipe entity has a relation one to one to Area and Line. The tag of Pipe is generated based on area.name and line.{some properties}, but this generation is based in an algorithm that can change (selecting some of line, some of area and some from pipe). That's why we think the best option is not to store the tag in the db because this algorithm changes over time and that means changing all the tag registries (there are hounded of thousands of them and increasing overtime).

So we have two options:

  • Pipe as and Aggregate and the Line and Area entities inside Pipe. This works fine because we always want to have line and area so we can generate on runtime the tag. The problem here is that when we are creating a pipe, we are using already created lines and areas, so we only need pipeId and areaId, so we have to call to the whole area and pipe repositories to be abled to create Pipe aggregate. The other problem is that the things inside an Aggregate shouldn't be accessible from the outside so we only could create an area via Pipe (pipe.createLine), but we want to create the areas and the lines first (independently) and then assign them to the pipe. Pipe(id, tag, train, area, line)

  • Pipe, Line and Area as diferent Aggregates. This solves the problem of creating independent areas and lines. But when i am searching a pipe, when i get it it says i have a tag, but i havent generate it, because i still have to search for the area and line and generate the tag and insert it to the Pipe. Pipe(id, tag, train, areaId, lineId)

Probably there may be intermediate solutions, but I haven't found them yet.Any help or link to a resource is welcome. Thank you very much!

  • Defining Pipe, Line and Area as separate aggregates.
  • Defining Pipe as an aggregate and Line and Area as entities inside it.
0

There are 0 best solutions below