2

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.

  • Can you explain fooId in more detail? Is this the Id of a different aggregate root instead of Book? Also, what are the flags that you speak of and what did you mean by they depend on the context? Could you provide some code examples? – Aaron Hawkins Oct 30 '14 at 15:59
  • Just made additional explanation – lawpert Oct 30 '14 at 16:24
  • It this a SaaS thing? Are you trying to support multiple totally-independent customers with the same domain? – Darien Oct 30 '14 at 19:55
  • Yeah, it's something like that - you may have independent books in the domain - per each group. Imagine company structure (group) where each group may have it's own groups. But also, we want to have books without being away of the group, as they may be no groups at all. – lawpert Oct 30 '14 at 20:52
1

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.

  • Using code generator is very tempting, I admit. (it is also sign of a weakness of the language, but that's not a point here). I just wonder if this is possible using just plain OO language. If we go to the code generators, I would then go to have full custom DSL language. Thank you, like the KISS approach :) – lawpert Nov 1 '14 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.