aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes helper functions good design? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "helper functions good design?" Watch "helper functions good design?" New topic
Author

helper functions good design?

Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
I usually avoid stuff like 'utility' packages or "Helper" classes.

However, I read in Head First OOA&D that It is a good idea to start out by creating a utility package for Helper classes.

What's your take?


comp.lang.javascript FAQ: http://jibbering.com/faq/
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I don't use them a lot. Sometimes they seem to make sense, but I always worry about the cohesion of my classes...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

I use helper classes and util packages, but I don't put them all in one util package. I do try to put logic where it belongs. But if multiple classes use the same logic, a helper class often makes sense. Or maybe I should say a helper object. Many of the helper classes don't have static methods.

For example:
mycompany.util - Generic things like StringUtil, DateUtil [this is the kitchen sink, everything goes in it package]
mycompany.component1.util - Helper classes having to do with a certain component


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Whether or not helper classes are a good idea depends largerly on whether they follow the object-oriented design principles and whether or not they introduce any code smells. The single responsibility principle sometimes drives the creation of helper classes as inclusion of their functionality could leave the core class with multiple responsibilties. Helper classes may also be created to stick with the DRY Principle (Do not Repeat Yourself); i.e. a piece of code that somehow seems to appear in all sorts of places needs to be consolidated in one place but doesn't have a natural home (though one should use this case very sparingly - it's more likely that you don't yet fully comprehend what's going on in your object model).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: helper functions good design?