Occasionally, an idea comes along that completely changes the way I think about developing software. Eric Evans' Domain-Driven Design: Tackling Complexity in the Heart of Software was one of those. As a database-first developer it suddenly seemed so obvious where I was going wrong.
The only trouble with Evans' book is that it very much deals in the abstract. Unlike other patterns books that give small snippets of code as examples, many of the DDD patterns in the book are left as an exercise for the reader. Some people have tried to remedy this, such as Jimmy Nilsson with his book
Applying Domain-Driven Design and Patterns: With Examples in C# and .NET but ultimately that was a good source of information with very little source code.
There is also much heated debate about how to implement these ideas online. Some people believe that just having a class called Repository in your code makes it DDD, others seem to be drawn in by the endless possibilities of the Specification pattern. There's very few examples of an end-to-end application though.
Tim McCarthy has bravely stuck his head above the parapet and written a full DDD example, and documented it in his book. I've just finished reading it, and here's a quick review of what I liked and disliked:
The Good:
- At last, some end-to-end source code!
- The book wisely stays away from the religious ORM argument, and just implements a repository using standard SQL. This allows more focus for the domain creation
- Because of this, other techniques that might usually be taken care of by an ORM, such as Unit Of Work, are created. I think this allows a better understanding of what they are there for.
- I quite like the implementation of the Specification pattern he uses, as it is similar to the way I use it.
The Not So Good:
- The first criticism is actually not directed at this book, but rather the Wrox "Problem - Design - Solution" books. This is the second one I have read, and both of them seemed to spend huge amounts of time describing the source code. If I want to see the source I can download it from Codeplex. I think the space would have been better spent going into more detail about the process of design, the thought behind some of the decisions and maybe more detail on the evolution of the code.
- As an example of this, on p70 McCarthy describes You Ain't Gonna Need It and then on p73 makes a class abstract because "who knows, later on having it as an abstract class might turn out to be useful". Fair enough, it was useful, but not at that moment...
- Although I've also listed it as a good point, the SQL repository can also be a bad point (you just can't win!). I think most people will use some ORM in their solution, so this could be a bit misleading. I wonder how easy it would be to do an NHibernate repository...
In summary, I would say that whilst Tim McCarthy has done a good job in bringing the idea of DDD to more people, the most benefit can be gained from downloading the code and studying it. There's too much regurgitated code from the source in the text of the book, and the space would have been much better used to describe some thought processes along the development path.