Search This Blog

Wednesday, December 4, 2013

Passing in more than needed

I finished Chapter 6 of Implementing Domain Driven Design. I am still not enjoying this book even though I will force myself to continue. Again the author promised many times he was going to reveal this really important bit of knowledge of how we are overusing entities and should be using value objects more in the domain. I thought he was going to talk about the return values from domain services and how those things are really important pieces of the UL. Instead his examples were more about avoiding primitive obsession. It is important information but I guess it was just not what I was hoping for. The next chapter is about Domain Services so maybe the information I am looking for is in there.

He did make one point I found interesting. He said that when you design a method definition you shouldn't pass in the whole entity if all you need is one value object off that entity. I have been doing the opposite lately. I try to make the client of the method as dumb as possible and put the logic of what needs to happen in the method doing the work. I find this makes reading my code easier. His point though was that you can't be sure that your method is side effect free if you pass in the whole entity. Also he said it makes testing harder to pass in the whole entity because you have to setup more data to pass to your method. I agree with both of his points. I am not sure I am ready to change my style yet, but the balance of pros and cons has definitely been shifted.

No comments:

Post a Comment