Our domain is operated within certain context. This context is described by some additional values, like a fooId
– id that does not have a meaning in domain business, but it’s more a flavor for the whole application and modules.
I need to store this fooId
with entities, like Book
. But I do not want Book
to have this id in the class, since number of flags depends on the context. This flags are available in the repo, so I am able to store them to the db.
How to model this?
I can have a factory for Book
that actually creates a Book
implementation that has all the additional fields. Repository would work only with these implementations. User is unaware of the additional fields. But he always need to call the Factory if he wants to create the object.
How does this feel? I do not see any other way to make this, and yet to have Book
not aware of additional flag(s).
The additional flags fooId
I am talking about may be e.g. groupId
. We can say that our software is dividied into modules, and each module may create it’s artifacts (like Books) in it’s own group. However, group is ‘flavor’ of the repository – services and model should not be aware of the groups, as we can have mono-group repo, where everything is stored in single group.
4
Problems of this kind can be solved by providing a graphical version of the model (for example, in an UML CASE tool), which shows just the domain attributes, together with a code generator which generates the implementation of class interfaces, database scripts etc.
The code generator will provide you silently with any of your “technical attributes”, so at the implementation level, they are visible and available, and on the “domain experts level”, the attributes are invisible. Moreover, your code generator can provide different code and different attributes for different contexts.
1