Helper methods, static vs. instance

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

    Helper methods, static vs. instance

    Memory usage wise is it a good idea to specify methods in utility/helper
    classes as instance methods rather than static methods?

    Rasika.
  • Jon Skeet [C# MVP]

    #2
    Re: Helper methods, static vs. instance

    Rasika <Rasika@discuss ions.microsoft. com> wrote:[color=blue]
    > Memory usage wise is it a good idea to specify methods in utility/helper
    > classes as instance methods rather than static methods?[/color]

    Quite the opposite - it would mean you'd have to create an instance in
    order to use the methods.

    However, memory shouldn't usually be your prime concern. Think about it
    in terms of object orientation - do these methods logically operate on
    an instance? If so, they should probably be instance methods. If not,
    they should probably be static methods. Helper classes almost always
    just have static methods.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Rasika WIJAYARATNE

      #3
      Re: Helper methods, static vs. instance

      Thank you!

      "Jon Skeet [C# MVP]" wrote:
      [color=blue]
      > Rasika <Rasika@discuss ions.microsoft. com> wrote:[color=green]
      > > Memory usage wise is it a good idea to specify methods in utility/helper
      > > classes as instance methods rather than static methods?[/color]
      >
      > Quite the opposite - it would mean you'd have to create an instance in
      > order to use the methods.
      >
      > However, memory shouldn't usually be your prime concern. Think about it
      > in terms of object orientation - do these methods logically operate on
      > an instance? If so, they should probably be instance methods. If not,
      > they should probably be static methods. Helper classes almost always
      > just have static methods.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too
      >[/color]

      Comment

      Working...