What’s That Funny Smell — Helper and Util?!?

I’ve been coding a long time and something I’ve come to realize over the last several years is that if you can’t come up with a good name for the class you’re working on, you probably have an outstanding design issue that you aren’t aware of yet. If your class includes the phrase “helper” or “util” then you need to come up with a better name. If you can’t, you’ve got a problem or you’re not really doing OOD. I’ve encountered a lot of designs filled with “Helpers” and “Utils.” I’m even guilty of writing a few in the past. But I urge you, for the sake of fellow coders everywhere, to come up with a better name and/or better design. “Helper” and “Util” don’t really tell me anything about your class other than it’s very likely to exhibit low cohesion.

If you’re writing Helpers and Utils, I bet they’re filled with static methods too. ARG!! Static methods can’t be part of interfaces which means you’ve tightly coupled yourself to a specific class, not an interface. As a result, you can’t easily write unit tests nor can you substitute a differnet implementation without renaming classes. All ugly, very ugly!!! I implore you to stop writing static methods. Object creation is highly optimized nowadays. New X().Method() is likely to be almost as (if not as) fast as X.Method(). Not that you’d really want to use that, but I’m just trying to ease you away from the static members. You will want to inject an instance of X somewhere in your run-time object hierarchy.


One Response to “What’s That Funny Smell — Helper and Util?!?”

  1. Chris Vance Says:

    Thanks for the reminder on good OOD. You’ll probably find solace in http://c2.com/cgi/wiki?HelperIsaCodeSmell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: