I’ve decided to use DDD in one of my pet projects to find out what the fuss is about! Let me start off by saying that this (DDD) is the way software SHOULD be written, I’ve seen some strange patterns and conventions but DDD is really the most natural way of writing code.
Interesting points that I noted started with DDD:
- I can now dream about code without being reminded of constraints set upon us by databases Persisting data now takes the backseat when developing a complex system (This might come back to bite me)
- I feel a lot closer to the business and business problem at hand
- Discussions between you and the client is now done on their neutral ground
- Discussions between developers are in line with the code
- I learned to love refactoring (You better make peace with that right now)
Question 1: Is an entity allowed to make repository calls? For instance, if you need to validate that a certain field is unique in the system, should you write a domain service or can the entity make a call to the repo?
Question 2: What is the best practice for validating a new entity? Should you have a Validate() function, or can the validation be done in the constructor?
Your thoughts on this?