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

30 Dec 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.


Using Semantic Types

6 Jan 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.


Using Consolidation

13 Jan 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.


With Relocation

20 Jan 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.


Using Premeditation

27 Jan 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.