aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Utils classes: code smell / antipattern? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Utils classes: code smell / antipattern?" Watch "Utils classes: code smell / antipattern?" New topic
Author

Utils classes: code smell / antipattern?

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Would anybody like to share their experiences with classes named ???Utils that were really not "utility" classes. The "util" classes that I'm looking at right now have a lot of business type logic and are smelling a lot like "I don't really know where to assign this responsibility so I'm just going to let the Utils class handle it."
[ June 04, 2004: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Yeah, if there's business logic in there it's probably smelly. Assigning responsiblity is what OO coder/designers get paid for. Shirking the job is smelly, too.

Some people reserve the name "utility class" for a class with all static methods, like Math. Every project probably has a StringUtils class. (What does that tell us?) Other people say classes should be responsibility plus state and if your static util class holds no state it's a smelly class. I'm in the first camp, by the way.

I recently made a couple stateless classes with all static methods that simplify kinda complex remote calls. I just got sick of typing the same four or five lines all the time and made a method that does them for me. We call them "helper" or "convenience" classes rather than "utility".
[ June 06, 2004: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Utils classes: code smell / antipattern?