Iterative Book Review

While at the Software Architect conference I picked up a copy of Tim McCarthy’s .NET Domain-Driven Design with C# I’m a little way into the book and thought I would have a post that iteratively reviewed how I found chapters as I come across them as this should give more insight.

Firstly this is the first time I have really looked into DDD properly I have read a number of books and articles that demonstrate using patterns & best practices but nothing that has been so specific to DDD such as defining Aggregate & Value objects, so I’m looking at this having not read the infamous Eric Evans or Jimmy Nilssons books which may not be a good thing as Tim does recommend reading them first, ah well 🙂

Things I like so far

  • The whole book is devoted to building a real world application so you get a good feel as to how you would apply the techniques to your own projects, great stuff!
  • The source code is up on codeplex
  • Nice introduction to the project and how it is going to be architect ed along with answers to the decisions made
  • Unit tests
  • Use of the Model-View-ViewModel using WPF (is this the same as Presentation Model?)

Things I ain’t to keen on

  • The Custom OR/M I think it would have been better and more clearer to use nHibernate or another available OR/M the custom one seems to add extra complexity with very little of the power gained by using an established OR/M (in defence Tim does mention had they not dropped it from vs2008 he would have used the Entity Framework)
  • Too much use of static factories, I would have preferred to have seen an existing IoC container being used this would have led to more testable code favouring DI rather than asking static factory classes for instances
  • Repository classes having lots of responsibility, I would be inclined to have a separate query builder object that the repositories just use, maybe in the later chapters this might be a refactoring
  • The service layers are static making them hard to unit test against

 These are early days and maybe some of the nuances may be sorted in later chapters, fingers crossed

Halfway update

Well I’m pretty much halfway through so I thought I would post some updates, one thing straight off the bat was some code I found to be a little off putting this is taken from the ProjectRespository class:

public override void PersistNewItem(IEntity item)
    Project project = item as Project;
    if (project != null)
        ProjectContact contact = item as ProjectContact;

 Along with a quote of:

Everything is still cleanly broken out and easy to maintain

I’m not so sure see to me the above looks to me like a bit of a code smell it breaks OCP, if we need to add other entities to save for this repository we then need to extend this method plus the other PersistXXX methods to accommodate. The problem stems from code that the repository classes inherit from and in this case the code above has to dodge against the code in the base class using a combination of method overrides and downcasting.

I have to say that going through the chapters it’s losing it’s appeal each feels pretty much the same as the last with so far nothing new being introduced since the first chapters.

Up till now I haven’t downloaded any of the code and have just been using the book as the guide, however today I went to codeplex to get the code as I wanted to come up with a good strategy for solving the code above and was regrettably disappointed nothing seems to work properly and the layout seems to be broken when saving projects I’m getting a MethodNotImplemented exception and when I think a save has worked it doesn’t actually persist to the DB I think that maybe this was too big of a project to use as an example and maybe only half of the features in there should have been implemented.

Summing up

I have reached the end of the book so here is a roundup, overall I was disappointed which is a shame as I very much liked having a real world example use of DDD but was let down by the design of some of the objects (overuse of Template pattern, too many static methods & strange use of Specification pattern spring to mind) and would certainly not use the same solutions as a most do not lend themselves to unit testing

I also became increasingly agitated by the amount of errors in the book wereby code was shown with a completely wrong description of what the code was doing in some cases it was clearly a copy & paste from the previous code section that had not been picked by the proof readers.

I could not recommend this for someone wanting to learn about DDD and instead I would probably just say  go and buy the Eric Evans book.