Probably whatever is the most efficent...Like if you have a small program that could be accomplished with an iterative loop, it would NOT be good practice to use recursion.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Static methods are not OO, and therefore not recommended by good OO approaches (which are best practice).
That's not to say they don't have their uses, but in strict OO design you will not find them.
At most some singletons and methods which have no instance specific functionality may be turned into static methods at some point if such yields superior performance.
Of course in reality that's often factored into the design as people get experienced enough to make such decisions at an early stage, but it's only the absolute beginners who make everything static, effectively abandoning OO altogether.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Buy yourself "Head First Design Patterns" by Eric and Elisabeth Freeman (0596007124).
It's an excellent book that explains not just the patterns but why and how to use them.
I knew the basic idea before reading that book and could recognise them, but couldn't for the life of me figure out how to apply that knowledge consistently.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Maybe it's just me, but I wouldn't "modify" anything to be static unless it's a utility class like Math, or if I really have to. I've seen a few people that say make everything static unless you don't need to, which I don't agree with. I guess a lot of people get tripped up when using the main method since it cannot reference anything but static contexts.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
yes, making main static may have been the worst design decision James and his team made when designing the language.
Or maybe it was providing for static stuff at all :)
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
That's part of it, but best practice extends to code written...In my opinion. For example, use methods and utility classes as much as you can, rather than re-inventing the wheel. Also, definately leave out repetitive code.
The list could go on and on, but that's just a few points.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Best practice can be anything from code layout to algorithms and design patterns used to business processes and procedures depending on the level you're talking at.
Use of UP for software design is a best practice, use of version control, unit testing frameworks, etc. etc.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337