| | |
What means "best practice"?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Can you post an exaple of where "best practice" is used?
PETA People for the Eating of Tasty Animals.
FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
FireFox
Hijack This
Ad-Aware
Hijack this tutorial
Microsoft AntiSpyware
CompUchat
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
Thanks OurNation,
There are many examples. For example, you can search "best practice" in http://java.sun.com, and you can find many of them.
regards,
George
•
•
•
•
Originally Posted by OurNation
Can you post an exaple of where "best practice" is used?
regards,
George
Anyone know of some simple best practice lists somewhere? Searching the sun link above is a bit blinding.
Here is a simple issue which new Java programmers meet quite quickly...
If I write a class that will be instantiated ONLY once is it best practice to put most of the initialisation code in the initialiser block or in the constructor?
In many cases there is loads of code that would work in either position because it is pre-configuring instance variables before they are used or displayed.
For trivial classes this doesn't make much difference but as classes grow it gets more important to have a clear structure or sequence for the initialisation code.
Here is a simple issue which new Java programmers meet quite quickly...
If I write a class that will be instantiated ONLY once is it best practice to put most of the initialisation code in the initialiser block or in the constructor?
In many cases there is loads of code that would work in either position because it is pre-configuring instance variables before they are used or displayed.
For trivial classes this doesn't make much difference but as classes grow it gets more important to have a clear structure or sequence for the initialisation code.
This ref covers some useful basic stuff on layout.
http://java.sun.com/docs/codeconv/CodeConventions.pdf
Umfortunately it doesn't extend to my initialisation code issue et al.
Anyone have a link to something that takes it a bit further?
http://java.sun.com/docs/codeconv/CodeConventions.pdf
Umfortunately it doesn't extend to my initialisation code issue et al.
Anyone have a link to something that takes it a bit further?
If the class only needs to be instantiated once, does it need to be instantiated at all? Why not use static methods? My personal preference is to avoid adding object-orientation that doesn't have to be there - it makes everything seem cleaner, somehow. This also takes care of the constructor vs init method issue - if there's no instantiation, there's no constructor.
Just a thought.
Just a thought.
Vi veri veniversum vivus vici
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.
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
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.
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- google "keyword" question (Search Engine Optimization)
Other Threads in the Java Forum
- Previous Thread: Rezisable Panels?
- Next Thread: run the number to the word equivalent
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api appinventor apple applet application arguments array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component database draw eclipse error event exception file fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health helpwithhomework html ide image input integer j2me java javaprojects jetbrains jmf jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie notdisplaying number object oracle page print problem program programming project qt recursion scanner screen server set size sms socket sort spamblocker sql string swing system test threads time tree variablebinding windows xor






