what is a helper class ?

Discussion in 'Java' started by gk, Sep 22, 2006.

  1. gk

    gk Guest

    Hi,

    I want to know , what is a helper class ?

    i have seen this term is frequently used in EJB, JAVA ,JSP in many
    places.

    and it seems to me they have different meaning in different context.

    is it so ?

    I found normal java classes are helper classes.

    why they are called helper then ....does it help ? help to whom ?


    can you please show me an example of helper class and tell me how it
    helps ?
     
    gk, Sep 22, 2006
    #1
    1. Advertising

  2. gk

    Stefan Ram Guest

    "gk" <> writes:
    >I want to know , what is a helper class ?


    The authors using this term are indeed to blame, because it
    just shows their lack of ability or desire to search for a
    specific designation.

    Sometimes, for example, it might be a class lacking proper
    cohesion and just containing different (static) methods for
    several purposes. A properly modelled class system should not
    have "helper classes" in this sense.

    Other times, it might mean something else.

    >why they are called helper then ....does it help ? help to whom ?


    Help the user of the term not to think of a better wording.
     
    Stefan Ram, Sep 22, 2006
    #2
    1. Advertising

  3. gk wrote:

    > I want to know , what is a helper class ?


    Someone sets out to write a class C that does something. After a while,
    the author realizes it would be useful to have a separate class D to do
    some of the work. The author writes class D purely to support class C;
    D is never used except as part of the implementation of C. D is a
    helper class.

    I tend to agree with Stefan that if you need a helper class, you're
    generally better off designing the class in a generalized fashion, such
    that it has the potential to be useful in other contexts than the one
    that inspired its creation. For example, Java has an interface called
    FileFilter, but in my own code, I have Filter<T>, such that concrete
    classes can extend Filter<File>, or Filter<Integer>, or whatever,
    without requiring a new interface for each type of filter. If you do
    this successfully, you won't end up with any pure "helper" classes. The
    name HelperClass is not particularly useful from a documentation
    standpoint, either.
     
    Jeffrey Schwab, Sep 22, 2006
    #3
  4. gk

    Chris Smith Guest

    Jeffrey Schwab <> wrote:
    > I tend to agree with Stefan that if you need a helper class, you're
    > generally better off designing the class in a generalized fashion, such
    > that it has the potential to be useful in other contexts than the one
    > that inspired its creation.


    This depends on the situation.

    If adding the new abstraction causes you to do anything differently from
    the way you would do it in a more specific case, then the new way is in
    that respect inferior for the originally intended purpose. It's then
    time to compare that cost against the potential for re-use, and make an
    informed decision. As one input into that informed decision, consider
    that reuse is the most over-rated of all the frequently listed
    advantages to object oriented programming.

    > If you do this successfully, you won't end up with any pure "helper"
    > classes.


    Considering that a "helper" class doesn't really have much meaning
    beyond a class that handles part of the work of building an abstraction,
    eliminating helper classes is a rather poor goal. Well-designed object
    oriented applications end up looking like a layered system of
    abstractions. From the perspective of any higher level of abstraction,
    *any* class belonging to a lower abstraction level can reasonably be
    described as a "helper" class.

    > The name HelperClass is not particularly useful from a documentation
    > standpoint, either.


    Certainly not as end-user documentation, nor as the only description of
    what a class does.

    --
    Chris Smith
     
    Chris Smith, Sep 23, 2006
    #4
  5. gk

    gk Guest

    Jeffrey Schwab wrote:
    > gk wrote:
    >
    > > I want to know , what is a helper class ?

    >
    > Someone sets out to write a class C that does something. After a while,
    > the author realizes it would be useful to have a separate class D to do
    > some of the work. The author writes class D purely to support class C;
    > D is never used except as part of the implementation of C. D is a
    > helper class.



    ok.

    suppose i wrote a bean class

    class C
    {
    D mydobject;
    //get

    // set
    }

    class D
    {
    //get
    //set

    }



    can we say D is now a Helper class ? look i have made D as a member
    variable of class C.





    > I tend to agree with Stefan that if you need a helper class, you're
    > generally better off designing the class in a generalized fashion, such
    > that it has the potential to be useful in other contexts than the one
    > that inspired its creation. For example, Java has an interface called
    > FileFilter, but in my own code, I have Filter<T>, such that concrete
    > classes can extend Filter<File>, or Filter<Integer>, or whatever,
    > without requiring a new interface for each type of filter. If you do
    > this successfully, you won't end up with any pure "helper" classes. The
    > name HelperClass is not particularly useful from a documentation
    > standpoint, either
     
    gk, Sep 23, 2006
    #5
  6. gk wrote:
    > Jeffrey Schwab wrote:
    >> gk wrote:
    >>
    >>> I want to know , what is a helper class ?

    >> Someone sets out to write a class C that does something. After a while,
    >> the author realizes it would be useful to have a separate class D to do
    >> some of the work. The author writes class D purely to support class C;
    >> D is never used except as part of the implementation of C. D is a
    >> helper class.

    >
    >
    > ok.
    >
    > suppose i wrote a bean class
    >
    > class C
    > {
    > D mydobject;
    > //get
    >
    > // set
    > }
    >
    > class D
    > {
    > //get
    > //set
    >
    > }
    >
    >
    >
    > can we say D is now a Helper class ? look i have made D as a member
    > variable of class C.


    It's impossible to tell whether D is a mere helper class from the code
    you have shown. The fact that C has a member of type D does not tell us
    whether it is a helper, or a concrete type, or just some object with
    which C interacts. For example, a graphical component can have a
    reference to its parent container, but that does not make the parent
    container's type a helper class for the component.
     
    Jeffrey Schwab, Sep 23, 2006
    #6
  7. Chris Smith wrote:
    > Jeffrey Schwab <> wrote:
    >> I tend to agree with Stefan that if you need a helper class, you're
    >> generally better off designing the class in a generalized fashion, such
    >> that it has the potential to be useful in other contexts than the one
    >> that inspired its creation.

    >
    > This depends on the situation.
    >
    > If adding the new abstraction causes you to do anything differently from
    > the way you would do it in a more specific case, then the new way is in
    > that respect inferior for the originally intended purpose. It's then
    > time to compare that cost against the potential for re-use, and make an
    > informed decision.


    You have a good point, but I don't know that a generalized solution is
    automatically inferior to a custom solution, any more than hand-made
    goods are automatically superior to machine-manufactured alternatives.
    Implementing a class in the most general possible way has the nice
    side-effect of distilling the exact concept the class is meant to
    represent, and helps keep fundamentally separate logic wherever it
    really belongs. You're right that generalization isn't always worth the
    time, though, nor is it guaranteed to improve the product as a whole.

    > As one input into that informed decision, consider
    > that reuse is the most over-rated of all the frequently listed
    > advantages to object oriented programming.


    Is that still true? It certainly used to be. I hear more about
    maintainability and logical correctness than about reusability nowadays.
    It seems like fat interfaces were in vogue for a while, with classes
    trying to be all things to all people in the wan hope of potential
    reuse. Now we seem to have swung to the opposite extreme, with lots of
    tiny, immutable objects being the hallmarks of best practice.

    >> If you do this successfully, you won't end up with any pure "helper"
    >> classes.

    >
    > Considering that a "helper" class doesn't really have much meaning
    > beyond a class that handles part of the work of building an abstraction,
    > eliminating helper classes is a rather poor goal.


    Nonsense. By that definition, all classes are helper classes. You
    might as well throw the term away entirely. Do you actually find that
    your released code has lots of classes called DoohickeyHelper? I bet it
    doesn't, because you are an experienced developer, and you probably know
    better.

    > Well-designed object
    > oriented applications end up looking like a layered system of
    > abstractions.


    True. I think that's true of good procedural programs, too, but even
    more so of OOP.

    > From the perspective of any higher level of abstraction,
    > *any* class belonging to a lower abstraction level can reasonably be
    > described as a "helper" class.


    You could choose to view it that way, but I don't think it would be very
    useful. Primitive ints and doubles aren't just "helper types" by virtue
    of being low-level. I don't know whether anybody has assigned "helper
    class" a formal definition, but this certainly isn't the way it is used
    in practice.

    >> The name HelperClass is not particularly useful from a documentation
    >> standpoint, either.

    >
    > Certainly not as end-user documentation, nor as the only description of
    > what a class does.


    The end user shouldn't see the helper class at all, else it's part of
    the public interface, and not just a helper. I think a helper is, by de
    facto definition, part of the implementation code, but specifically not
    part of the interface.

    OTOH, if you really have a class that's just a place to dump some code
    related to Foo, then I suppose FooHelper is a reasonable name. What
    would bother me personally about that name is that it makes me feel the
    code probably belongs in Foo proper, else it should not have been
    factored into a separate type.
     
    Jeffrey Schwab, Sep 23, 2006
    #7
  8. gk

    Mark Space Guest

    Jeffrey Schwab wrote:
    > gk wrote:
    >>
    >> can we say D is now a Helper class ? look i have made D as a member
    >> variable of class C.

    >
    > It's impossible to tell whether D is a mere helper class from the code
    > you have shown. The fact that C has a member of type D does not tell us


    Yes, Jeffrey is correct. My Java is a little rusty still, but I think
    this example might help:

    // All in file MyBean.java
    public class MyBean {
    void setA ( ... ){...};
    String getA () {...};
    // Many more methods...
    // ...
    }
    class MyBeanHelper {
    // Methods here to help MyBean
    }

    Note that the name is unimportant. MyBeanHelper is a private class that
    is only accessible from within the MyBean.java file. That means it's
    probably got only one function, something to do with MyBean. Since it
    isn't the MyBean class itself, it's safe to assume that it's a helper
    class for MyBean.
     
    Mark Space, Sep 23, 2006
    #8
  9. gk

    gk Guest

    Mark Space wrote:
    > Jeffrey Schwab wrote:
    > > gk wrote:
    > >>
    > >> can we say D is now a Helper class ? look i have made D as a member
    > >> variable of class C.

    > >
    > > It's impossible to tell whether D is a mere helper class from the code
    > > you have shown. The fact that C has a member of type D does not tell us

    >
    > Yes, Jeffrey is correct. My Java is a little rusty still, but I think
    > this example might help:
    >
    > // All in file MyBean.java
    > public class MyBean {
    > void setA ( ... ){...};
    > String getA () {...};
    > // Many more methods...
    > // ...
    > }
    > class MyBeanHelper {
    > // Methods here to help MyBean
    > }



    How its going to help MyBean class ?

    whats the relationship with MyBeanHelper class and MyBean class.

    you told MyBeanHelper helps MyBean class...but how ?






    >
    > Note that the name is unimportant. MyBeanHelper is a private class that
    > is only accessible from within the MyBean.java file. That means it's
    > probably got only one function, something to do with MyBean. Since it
    > isn't the MyBean class itself, it's safe to assume that it's a helper
    > class for MyBean.
     
    gk, Sep 24, 2006
    #9
  10. gk

    Ed Guest

    gk skrev:

    > Hi,
    >
    > I want to know , what is a helper class ?
    >
    > i have seen this term is frequently used in EJB, JAVA ,JSP in many
    > places.
    >
    > and it seems to me they have different meaning in different context.
    >
    > is it so ?
    >
    > I found normal java classes are helper classes.
    >
    > why they are called helper then ....does it help ? help to whom ?
    >
    >
    > can you please show me an example of helper class and tell me how it
    > helps ?


    Rather than the interesting replies you've received so far, here's some
    boring, home-grown examples.

    I'd consider the three LocalLibrary classes are helper-classes here:
    http://www.edmundkirwan.com/servlet/fractal/cs1/code/all-link0.html

    I'd consider the FrequencyAnalysis class a border-line helper-class
    (border-line because it seems less transportable, somewhow; just a
    feeling):
    http://www.edmundkirwan.com/servlet/fractal/cs1/code/package100.html

    ..ed

    --
    www.EdmundKirwan.com - Home of The Fractal Class Composition.

    Download Fractality, free Java code analyzer:
    www.EdmundKirwan.com/servlet/fractal/frac-page130.html
     
    Ed, Sep 25, 2006
    #10
  11. gk

    maas Guest

    i think you can define a 'helper class' or a 'helper method' as
    something that's not 'conceptually' connected to your application,
    having no meaning attached to it, serving solely for "helping" other
    classes. It has nothing to do with visibility or encapsulation
    (public/private...) although you are not expected to use 'helper'
    functions from any library.

    maas

    -
    www.marcosaurelio.com

    gk wrote:
    > Mark Space wrote:
    > > Jeffrey Schwab wrote:
    > > > gk wrote:
    > > >>
    > > >> can we say D is now a Helper class ? look i have made D as a member
    > > >> variable of class C.
    > > >
    > > > It's impossible to tell whether D is a mere helper class from the code
    > > > you have shown. The fact that C has a member of type D does not tell us

    > >
    > > Yes, Jeffrey is correct. My Java is a little rusty still, but I think
    > > this example might help:
    > >
    > > // All in file MyBean.java
    > > public class MyBean {
    > > void setA ( ... ){...};
    > > String getA () {...};
    > > // Many more methods...
    > > // ...
    > > }
    > > class MyBeanHelper {
    > > // Methods here to help MyBean
    > > }

    >
    >
    > How its going to help MyBean class ?
    >
    > whats the relationship with MyBeanHelper class and MyBean class.
    >
    > you told MyBeanHelper helps MyBean class...but how ?
    >
    >
    >
    >
    >
    >
    > >
    > > Note that the name is unimportant. MyBeanHelper is a private class that
    > > is only accessible from within the MyBean.java file. That means it's
    > > probably got only one function, something to do with MyBean. Since it
    > > isn't the MyBean class itself, it's safe to assume that it's a helper
    > > class for MyBean.
     
    maas, Sep 25, 2006
    #11
  12. gk

    Mark Space Guest

    gk wrote:

    > How its going to help MyBean class ?


    Just by being there. :) Presumably it has some methods for MyBean to
    call, but there might be other ways too.

    >
    > whats the relationship with MyBeanHelper class and MyBean class.


    They are in the same file. That's all.

    >
    > you told MyBeanHelper helps MyBean class...but how ?
    >


    Method invocation, or instantiation. There is no formal relationship
    other than both classes exist and one (the helper) has no other
    relationship with any other part of the program.
     
    Mark Space, Sep 26, 2006
    #12
  13. gk

    sparkle

    Joined:
    Mar 2, 2012
    Messages:
    1
    Although a Java program is sometimes called a class, there are many occasions when a program requires more than one class to get its work done. A multiclass program consists of a main class and any helper classes that are needed. These helper classes earn their name by helping the main class do its work.

    Link reference: http://www.informit.com/library/content.aspx?b=STY_Java2_24hours&seqNum=129
     
    sparkle, Mar 2, 2012
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arijit Mukherjee
    Replies:
    0
    Views:
    696
    Arijit Mukherjee
    Jan 2, 2004
  2. Mario S.
    Replies:
    0
    Views:
    479
    Mario S.
    Apr 1, 2004
  3. Crocodile

    Convenience class vs helper class

    Crocodile, Sep 22, 2008, in forum: Java
    Replies:
    0
    Views:
    466
    Crocodile
    Sep 22, 2008
  4. Nephi Immortal

    Helper class uses main class' pointer

    Nephi Immortal, Feb 8, 2011, in forum: C++
    Replies:
    1
    Views:
    469
    Saeed Amrollahi
    Feb 9, 2011
  5. kevin
    Replies:
    1
    Views:
    387
    Kairi Zikpin
    Jul 21, 2006
Loading...

Share This Page