473,947 Members | 28,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is a helper class?

I have heard about helper classes, but can somebody please explain to me
what they are and what they are used?

*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '07 #1
6 49779
Mike P <mi*******@gmai l.comwrote:
I have heard about helper classes, but can somebody please explain to me
what they are and what they are used?
They're usually classes just with static methods acting on another
class. Something like:

public static class StringHelper
{
public static string Reverse(string input)
{
(Code goes here)
}
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 21 '07 #2
"Helper class" is just a term to refer to a class that provides methods that
"help" do something. A well - know example is the Data Access Application
Blocks v2 "SqlHelper" class, which helps perform common data access functions.

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Mike P" wrote:
I have heard about helper classes, but can somebody please explain to me
what they are and what they are used?

*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '07 #3
Another example is : HttpUtility class.
--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
"Mike P" wrote:
I have heard about helper classes, but can somebody please explain to me
what they are and what they are used?

*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '07 #4
Jon,

What would be the reason for creating a class just with static methods
acting on another class?
Thanks,

Mike
*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '07 #5
Mike P <mi*******@gmai l.comwrote:
What would be the reason for creating a class just with static methods
acting on another class?
It collects them together. Often you can't add methods to a class
itself, because you don't have the code - I can't add the Reverse
method to string, for example.

If you're going to frequently do the same things with an instance of a
class, it's worth putting that somewhere rather than repeating the
code.

Another example is in my miscellaneous utility library
(http://pobox.com/~skeet/csharp/miscutil) - I've got a helper class for
working with streams. It has a set of methods to copy the contents of
one stream to another, and another set to read the complete contents of
a stream as a byte array.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 21 '07 #6
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Mike P <mi*******@gmai l.comwrote:
>What would be the reason for creating a class just with static methods
acting on another class?

It collects them together. Often you can't add methods to a class
itself, because you don't have the code - I can't add the Reverse
method to string, for example.
You can with C# V3.0 by adding "this" to the methods argument, ie:

public static class StringHelper
{
public static string Reverse(this string input)
{
(Code goes here)
}
}

....

using StringHelper;

string myString;
....

string reveresedString = myString.Revers ed();
Aug 21 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1285
by: Mario S. | last post by:
Hi, I use Xerces 2.5 since 2 weeks for creating/parsing xml documents. It's important to have the best performance here. I use always the Macro X() which instantiate helper class XStr() to transcode the string in the right way. I tool this XStr() out from the sample codes delivered by Xerces. There is a comment in source above the XStr() class definition: // -------------------------------------------------------------------------
1
340
by: amber | last post by:
Hello, I'm using Microsoft Application Blocks in a project I'm working on. I now need to populate a single dataset, that consists of 2 tables. From what I've read, if I wasn't using MS Application Blocks, it would simply be dataAdapter1.fill(dataset1("table1") dataAdapter1.newSelectCommandHere dataAdapter1.fill(dataset1("table2")
6
2495
by: Alex Hunsley | last post by:
I know that I can catch access to unknown attributes with code something like the following: class example: def __getattr__(self, name): if name == 'age': return __age else: raise AttributeError
4
5641
by: Rahul Anand | last post by:
Getting SQL Exception when trying to implement Connection based Trasaction using SQL Helper class. I am using the follwing function to execute my stored procs: -=-=-=- ExecuteScalar(ByVal transaction As SqlTransaction, _ ByVal spName As String, _ ByVal ParamArray parameterValues() As Object)
2
1923
by: WB | last post by:
Hi, How can I access Server and Trace within a helper class? I have a webform that allows user to select a PDF file (on the web server) and render a jpeg image of that PDF file. The helper class has a method like this: public void ProcessFile(string virtualPath, string outputFilename) {
3
3283
by: oaklander | last post by:
I have a JDBC working with Oracle 9i in my Tomcat 4.1.3 Container. The Database classes I have used for the past year are working great but I wonder if I should be closing anything in my database helper class with Prepared statements: public class DbInsert { private PreparedStatement stat; private Connection connection; public DbInsert(Connection connection)
3
2017
by: Hongyu | last post by:
Hi, I am a newbie in C++. I saw a code like the below and don't understand it. class A { public: A();
13
2762
by: Hussein B | last post by:
Hi, I'm familiar with static method concept, but what is the class method? how it does differ from static method? when to use it? -- class M: def method(cls, x): pass method = classmethod(method) --
0
10162
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9982
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11573
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11156
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11346
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7429
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4945
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.