When to use domain driven design
Three mental models
In any software, there are at least three mental models at play. First, is the user’s mental model, her understanding of how the software works. Second, Domain expert’s mental model of how Software should work and lastly, developer’s mental model of how the software actually works. Generally, DDD does not talk much about the user’s mental model since it tries to isolate the core domain from representation and persistence concerns.
Why should we keep these mental models in sync
If you practice learning not only as an only accumulation of knowledge, but as a practice to build mental models to which information can stick, then you enter a feedback loop where learning facilitates learning.
– Charlie Munger
When these three mental models are in sync, there is one to one mapping between customers/domain experts mental model and the code. Any new requirement gets fairly easy/faster to implement. When not in sync, we would need to translate concepts from one mental model to another.
Without keeping these mental models in sync, you can always modify code in the ways you want without consulting a domain expert, but, the mental model of developer and domain expert would not match. In the beginning, the software will be small and understandable, It is not hard to synchronise the mental model of the developer and domain expert with few translations, however, complexity will grow with time and mental models will drift apart.
How Software should behave in view of changing requirements is something for domain experts to decide, but when mental models are not in sync, Domain experts have to rely on the mental model of developers to decide how should software behave. There will be a lot of translation happening and information is bound to be missed or misinterpreted.
Keeping mental models in sync
You can achieve this sync by being very rigorous about building these mental models. It doesn’t have to reflect reality, but whatever mental model we choose we should be rigorous about it and make sure everyone has the same mental model.
When to keep these mental models in sync aka when to use DDD
You don’t need DDD if your software doesn’t have too many of these translations. This is usually the case when the project is small enough or just started. However, Do keep an eye on these translations, if they get out of hand, It is time to do proper domain modelling.
Use DDD to simplify, not to complicate
Use DDD to model a complex domain in the simplest possible way. Never use DDD to make your solution more complex.