I wish that I could take credit for this article, but I can’t. Instead, I have to credit two people: Lasse Koskela and Miško Hevery. I credit Lasse for writing the manuscript that led me to Miško’s article. Look for Lasse’s upcoming book Unit Testing in Java at Manning Publications’ site. Let me summarize Miško’s article here, then you can read the details at his blog.
Why would I simply summarize someone else’s article on this site? Isn’t that dishonest? Not in this case: Miško wrote essentially the same thing that I say over and over again in my own articles and in my training classes. I consider it unfortunate that he and I have never met nor worked together. We really should. You should read his stuff.
So… 10 ways to kill your design.
- Instantiate Services wherever the hell you want.
- Grab what you want when you want it.
- Do real work in your constructors.
- Publicise state.
- Embrace singletons.
static. (Admittedly, this is more of a problem in Java/C# than Ruby/Python.)
- Inherit implementation.
- Reimplement polymorphism.
- Mix Services and Values.
- Keep conjunctions in your variable, method and class names.