Re: Help -- New to Java
- From: "Bjorn Abelli" <bjorn_abelli@xxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jul 2007 18:53:57 +0200
"Lew" <lew@xxxxxxxxxxxxxxxx> wrote...
Bjorn Abelli wrote:
The main difference from C in this aspect is that you need to
use the keyword "static". Otherwise it becomes an "instance
member" instead of a "class member".
No, you don't. This could just as well be an instance method.
Yes, he does, as his assignment explicitly says so... ;-)
You are correct. I was speaking outside the context of the OP's
homework, wasn't I?
I don't know, did you? ;-)
Actually, for methods the question of static vs. instance interests me.
Is there a best practice (when a manager hasn't forced the choice for
non-technical reasons)?
I lean towards making methods instance-level most of the time. For
non-instantiable utility classes I use only static methods and no
instance anythings.
This debate, or at least similar, has been going on for decades, somewhat
similar to discussions on when to make "functions" or "procedures" back in
the days before OO...
Among OO-purists, it's mostly considered bad practice to have static methods
at all.
On the other end of the spectrum, developers stuck in the old procedural way
of programming, some never use instances...
I would say that "best practice" should be quite pragmatic on this issue. If
you do a good OOAD, it usually falls quite naturally "what works". The
problem is rather that there are so many bad OOAD out there...
In this particular case, I guess the OP's forced to use static methods out
of two reasons;
- for some it's easier to grasp Java in the beginning by not using instances
- it follows Java's own use of static methods in the Math class.
/// Bjorn A
.
- References:
- Help -- New to Java
- From: Al
- Re: Help -- New to Java
- From: Bjorn Abelli
- Re: Help -- New to Java
- From: Lew
- Re: Help -- New to Java
- From: Bjorn Abelli
- Re: Help -- New to Java
- From: Lew
- Help -- New to Java
- Prev by Date: Re: Help -- New to Java
- Next by Date: Re: Log4J Ignores log4j.LogLevel
- Previous by thread: Re: Help -- New to Java
- Next by thread: Re: Help -- New to Java
- Index(es):
Relevant Pages
|