Most sizable codebases - especially the long lived ones - have a dumping ground, a “utility” class that acretes debris that has nowhere else to live. While a little debris can be tollerated as a necessary mess, many utility classes grow into deadly monsters that are dangerous. The good news is that they can be killed. The bad news is that it takes some work.

Using Extension Methods

Saturday, December 30 2017 utility-class smart-code

Think about the larger projects you’ve worked on during your career. Did you have a dumping ground for odd pieces of functionality? Perhaps a utility class or even multiple multiple utility classes? It’s a very common thing to see a utility class in any codebase of reasonable size, especially one that has been around for a while.

Read more »

Using Semantic Types

Saturday, January 06 2018 utility-class smart-code

Following on from our discussion on extension methods, another technique you can use when eliminating the dumping ground of your utility class is the extraction of buried semantic types. This is possible when you find a set of closely related methods with linked semantics.

Read more »

Using Consolidation

Saturday, January 13 2018 utility-class smart-code

Sometimes your utility class will contain methods that smell strongly of feature envy, prompting you to relocate them onto an existing class. This is a much simpler cleanup than introducing a semantic type.

Read more »

With Relocation

Saturday, January 20 2018 utility-class smart-code

Sometimes you’ll find a method on your utility class that’s only used once - or only from a single consuming class. This frequently happens when a developer genuinely believes the method will be generally useful and should be available for reuse, but is wrong.

Read more »

Using Premeditation

Saturday, January 27 2018 utility-class smart-code

If you have a utility class in your current code base, there’s something very important you should do - even before you apply any of the techniques we’ve discussed previously.

Read more »