I read a lot about DDD but few thing are still unclear. At this moment I have two dilemma
- The size of aggregates. How small could be an aggregate? For example we have:
class Car {
String colorId
(or String colorCode)
...other fields
}
class Color {
String code
}
I think in this case Color should be an aggregate with just one field and no business logic. The only choice is how to store information about color in aggregate - keep an Id of Color or keep value. Am I right?
- Relations between entities inside of different aggregates. Everywhere I read that it shouldn't happen. Is it mean that I shouldn't keep any kind of relation? What should I do in situations like that:
class Order {
List<OrderLine>
}
class OrderLine {
}
class Invoice {
List<InvoiceLine>
}
class InvoiceLine {
}
Probably we should have two aggregates: Order and Invoice but there could be N invoices to one order therefore we need to know which InvoiceLine coresponds with which OrderLine. It could be even more complicated if we allow to issue also one Invoice to many Orders.
In this situation I could:
- make 4 aggregates - but what with invariants? I won't be able to keep consistency i one document.
- make 1 aggregate - but if we have also another kinds of documents it will be a huge aggregate, "half a database" in one query
- 2 AG and keep Id of other line entity (it for sure breaks the rules of DDD)
- 2 AG but keep relation to lines by line number - each OrderLine/InvoiceLine has its own line number starting with 1 - I could refere to them through AG which have an unique Id and with line number which is unique in a scope of AG (is it break the rules of DDD?)
What is a proper way to solve this kind of problem?