Namespace for (DDD) entities cutting across domains

421 views Asked by At

I have a couple of business-related domains like Purchase, Marketing and Economy. Having the models arranged into a namespace* for each domain would be nice, but there are some entities cutting across domains, like an Item. How to organize those cross-cutting objects?

* = As in C#/Java/Python namespaces.

2

There are 2 answers

0
rafaels88 On BEST ANSWER

Since you have the concept of Bounded Context, you should not share domains between the namespaces. Actually, you should have one Item for each namespace that requires it, and each of those Item should have it's own fields as required by the context it is included.

As Eric Evans said, it is not a big deal replicate data in order to never share the same domain between contexts, but only data.

0
Eben Roux On

Determining whether you have the correct design will require some experience with the domain so you should check with your domain expert.

You may very well require a Shared Kernel for classes that are cross-cutting. You'll have to be careful that you do not abuse the shared kernel by placing too many generic / logical classes in there.

To add to what @rafaels88 has answered you may need to create a BC specific domain construct where some logical entity exists. For instance, a User in the Identity & Access Control BC would be an Author in one BC but perhaps a Supervisor in another.

You could also duplicate an AR in one BC as a VO in another. A Customer in the CRM BC may be the system of record for a customer and, therefore, contain a whole lot more information. In the Order BC, however, a Customer VO may only contain an Id, Name, and perhaps Address (for example).

So you will need to evaluate what type of object you have before deciding where to place it.