mercredi 29 juin 2022

How to model this case in DDD?

I'm facing the issue where either I can't apply DDD, or the case can't be reformulated to fit the DDD rules.

The requirements:

  1. We have a Product and Location.
  2. Change in Location should be reflected in Product which user then sees. Therefore Product references Location.
  3. Same Location might be used in several Products.
  4. Product might be created and deleted at any time point.
  5. Location might be created at any time point.
  6. Location might be deleted only if there is no Product references this Location.
  7. Delete of a Product does not lead to Location deletion.

There are two more entities in the model exist with the same rules as Location, but solution should be the same as with Location case.

My thoughts:

So the problem which I see, that such requirements creates circular dependency on Product and Location. Because they all have own unlimited life cycle they supposed to be separate aggregation roots, but then this violates the consistency boundary, as basically one AR is trying to control another AR. So, this invariant can't be placed in any of those two. Trying to extract this into third one on the top AR also not clear how this would work.

The question:

How can I satisfy such requirements in DDD? Removing the constraint 6 is not an option. I've already tried to negotiate this with business side.

Aucun commentaire:

Enregistrer un commentaire