what is a helper class?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike P

    #1

    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 ***
  • Jon Skeet [C# MVP]

    #2
    Re: what is a helper class?

    Mike P <mike.parr@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 - <skeet@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

    Comment

    • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

      #3
      RE: what is a helper class?

      "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 ***
      >

      Comment

      • =?Utf-8?B?WWFyb24gS2Fybmk=?=

        #4
        RE: what is a helper class?

        Another example is : HttpUtility class.
        --
        Sincerely
        Yaron Karni
        All .net c# stuff, patterns code and snippet help programmer.



        "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 ***
        >

        Comment

        • Mike P

          #5
          Re: what is a helper class?

          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 ***

          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: what is a helper class?

            Mike P <mike.parr@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 - <skeet@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

            Comment

            • John Vottero

              #7
              Re: what is a helper class?

              "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
              news:MPG.213505 9dc6a6f9fb3d5@m snews.microsoft .com...
              Mike P <mike.parr@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();


              Comment

              Working...