Search code examples
domain-driven-designaggregaterootbounded-contexts

DDD, Is it ok to have multiple aggregate root shared same identity in bounded context


Is it ok to have many aggregate root like this in a bounded context

Product
   ProductID : GUID
   Name : string
   Price : float

ProductPromotion
   ProductID : GUID
   Discounted : float

ProductShortName
   ProductID : GUID
   ShortName : string

I don't know it will break the rule of bounded context while these are difference kind of product but within a context.

link to my actual problem


Solution

  • Each Aggregate Root should have its own unique ID in a DDD scenario and that seems to be missing (if I'm understanding your scenario correctly, it seems you want all of the 3 classes to be roots). So, if your design was something along these lines:

    Product <ROOT>
       ProductID : GUID
       Name : string
       Price : float
    
    ProductPromotion <ROOT>
       PromotionID: GUID
       ProductID : GUID
       Discounted : float
    
    ProductShortName <ROOT>
       NameID: GUID
       ProductID : GUID
       ShortName : string
    

    on its own, this design doesn't hurt the aggregate or bounded context principles. One aggregate should be allowed to hold a reference to another aggregate root's id (as in countless shopping-cart examples where the LineItem holds a reference to the ProductID).

    What you shouldn't be doing (and it appears you aren't) is holding full references to whole aggregates inside another.

    However, you should always reflect on what are your goals when designing aggregates. Yes they should be small, but they also must convey an objective. Usually they are designed to enforce certain invariants and these examples don't seem to be achieving that goal.

    Maybe your example was overly simplified for the question though and I can't really evaluate it but it doesn't seem to me "ProductPromotion" and "ProductShortName" are good candidates for full aggregates the way they are presented.