Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
When do we decide a method is a 'helper' method? - I'm looking for a bit of definition here.

For some time now I've seen applications and APIs with regions in the source called something like 'Helpers' or 'Helper Methods'. What makes a method a 'helper' method?

Yes, granted the method provides some functionality that 'helps' - but what about more solid technical definition? For me I've never seen any consistent pattern - eg should the method be static or void?

I often see all sorts of methods referred to as helper methods but there never seems to be any consistency in their adornments, access modifiers or functionality...

Many Thanks
Posted

It is apparently also called a delegation pattern. The Wikipedia article is http://en.wikipedia.org/wiki/Delegation_pattern[^]
 
Share this answer
 
A nice description here "Helper Method"[^], however, I agree with Chris (Solution 1): probably everyone has his personal definition of 'helper method'.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 14-Jun-13 16:04pm    
5ed. My 1 cent: it would be safe enough to say that "helper method" does not really need a definition, so there is no a definition. It does not present any separate entity technically or mathematically. It simply reflects some pretty reasonable element of culture when engineers communicate; it rather reflects semantics with fuzzy meaning and, in particular, helps to name things the way other developers could understand them faster.
—SA
CPallini 14-Jun-13 16:11pm    
Wow, now that well deserves a 5, well said Sergey.
Sergey Alexandrovich Kryukov 14-Jun-13 16:28pm    
Thank you, Carlo.
—SA
You've an interesting question, there!

I suspect you'll not find any universal definition of helper method, just 1001 different personal takes on the subject.

So, here's mine...

A helper method is a method that 'targets' or relates to some class (perhaps entirely) but for some reason is not implemented as part of that class. Typically, the reason would be that the class is implemented in an unmodifiable body of code (an in house or 3rd party library, the .Net framework, etc.) AND where the extra work cannot, or does not justify, implementing a subclass.

An example of a helper method I've created is one that take a string and sticks in spaces in front of every captial letter (except at the beginning of the string). Takes a property name, or database column name, and makes something moderately more acceptable for users to see.

* Does it belong in the class where I want to get the new text? No.

* Can I extend System.String? No.

What to do? Create a helper method.

.Net kindly introduced extension methods a couple of generations ago. I love them. I find that they allow me to segregate such methods away from the consuming code (so I'm not 'polluting' the code of the class where I need the behaviour); in addition, they show up in the intellisense for the extended class.

I make it a personal rule to make the class(es) that implement my extension methods internal. That way they do not become a public API that needs to be properly documented for other developers on the team to understand, if they need to consume the assembly in which they are implemented.
 
Share this answer
 
Comments
John Bracey 14-Jun-13 15:48pm    
Many thanks for your response. I think there is a bit of interpretation with helper methods - personal interpretation as you say. I don't suppose it matters too much as long as there's consistency. An Architect/Team Lead/Dev Manager would want/advise consistency throughout an application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900