Wednesday, April 18, 2012

I hate fat classes.

Don't make fat classes and try to break them up with regions. Instead strive for an OCP approach in which fat classes are broken up into smaller ones. It will make testing much easier. There is nothing more frustrating than putting a method into an existing fat class that is not under test and then trying to merely get the method you added under test. You can spend hours on a scavenger hunt trying to find all of the dependencies to mock just in the name of surviving the trip through the constructor in test without exception. This headache will make you NOT want to test. You'll understand why there weren't tests there to begin with and once you get tests there you will find them hard to maintain as new dependencies to mock materialize. Why? Because the class in question is doing too much!

No comments:

Post a Comment