Your ctor says that your code is headache inducingExplanation

time to read 2 min | 289 words

I was pointed to this codebase, as a good candidate for review. As usual, I have no contact with the project owners, and I am merely using the code as a good way to discuss architecture and patterns.

It starts with this class:


Okay, this codebase is going to have the following problems:

  • Complex and complicated
  • Hard to maintain
  • Hard to test
  • Probably contains a lot of code “best practices” that are going to cause a lot of pain

And I said that this is the case without looking at any part of the code except for this constructor. How am I so certain of that?

Put simply, with 9 dependencies, and especially with those kind of dependencies, I can pretty much ensure that this class already violate the Single Responsibility Principle. It is just doing too much, too complex and too fragile.

I shudder to think what is involved in testing something like that. Now, to be fair, I looked at the rest of the codebase, and it seems like I caught it in a state of flux, with a lot of stuff still not implemented.

Nevertheless… this is a recipe for disaster, and I should know, I have gone ctor happy more than once, and I learned from it.

And here is the obligatory self reference:


And yes, this does give me a headache, too.

More posts in "Your ctor says that your code is headache inducing" series:

  1. (20 Oct 2011) Explanation
  2. (19 Oct 2011) Introduction