Helper methods, static vs. instance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

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

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.
 
Thank you!

Jon Skeet said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top