469,352 Members | 1,656 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

static private methods

Hi

I have been in the habit, when extracting a private "helper" method
from a public method, of marking it "static" wherever possible -- that
is, when it does not reference instance variables or other non-static
methods. My rationale is that when browsing the source, such methods
can be initially ignored, as they can have no side-effect on the
instance.

However, i have noticed that it does not appear conventional in the
java community to do this.

Is my convention helpful? Or is it "against the grain" of the language
in some way that i am not aware of?

Thanks in advance,

Paul MG.
Jul 17 '05 #1
4 10439
Paul MG wrote:
Hi

I have been in the habit, when extracting a private "helper" method
from a public method, of marking it "static" wherever possible -- that
is, when it does not reference instance variables or other non-static
methods. My rationale is that when browsing the source, such methods
can be initially ignored, as they can have no side-effect on the
instance.

However, i have noticed that it does not appear conventional in the
java community to do this.

Is my convention helpful? Or is it "against the grain" of the language
in some way that i am not aware of?

Thanks in advance,

Paul MG.


Interesting idea, I can't see any good reason for it "harming" the code
but it would certainly throw me a curve ball if I had to maintain it. I
would certainly say that it is against the grain.
Jul 17 '05 #2
I take the opposite view, and never use static methods at all.
The big disadvantage is that once a method is static, it cannot be
overridden in subclasses. You may not want to now, but as the code
evolves, you may very well.

One common view is that if a method does not change the state of an
instance, it does not belong in that class, but in some other 'utility'
class.

Benedict
Jul 17 '05 #3
I tend to do this as well. I can't comment on whether this goes "against
the grain", but in my mind it makes the utility methods more apparent. If I
end up with several of these in a single class, I'll put them in a utility
class with a private constructor. I also use the "final" keyword a lot to
restrict subclassing and method overriding. The projects I work on tend to
have very shallow class hierarchies.

-Eric

"Paul MG" <pa****@digitalbrain.com> wrote in message
news:26**************************@posting.google.c om...
Hi

I have been in the habit, when extracting a private "helper" method
from a public method, of marking it "static" wherever possible -- that
is, when it does not reference instance variables or other non-static
methods. My rationale is that when browsing the source, such methods
can be initially ignored, as they can have no side-effect on the
instance.

However, i have noticed that it does not appear conventional in the
java community to do this.

Is my convention helpful? Or is it "against the grain" of the language
in some way that i am not aware of?

Thanks in advance,

Paul MG.

Jul 17 '05 #4
benedictheal wrote:
One common view is that if a method does not change the state of an
instance, it does not belong in that class, but in some other 'utility'
class.


And that should be the only view ;-)

--
Michael Banzon
http://michael.banzon.dk/
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by MaxMax | last post: by
3 posts views Thread by Jay | last post: by
10 posts views Thread by McFly Racing | last post: by
8 posts views Thread by Fernando Lopes | last post: by
4 posts views Thread by Rene | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.