| Author |
By convention - are there for exemple first variables, second getters and setters and third methods?
|
André Asantos
Ranch Hand
Joined: Nov 23, 2009
Posts: 234
|
|
|
By convention - are there for exemple first variables, second getters and setters and third methods into the class?
|
André AS
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
Do you mean the order they are in the source file ?
|
[My Blog]
All roads lead to JavaRanch
|
 |
André Asantos
Ranch Hand
Joined: Nov 23, 2009
Posts: 234
|
|
|
Exactly...
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
Personally, I prefer to have all instance variables at the top, and then methods (getters, setters included). I think it's the way it's done most of the time.
You can refer to the Code Conventions for the Java Programming Language.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
I usually use the following order:
1) static fields
2) instance fields
3) constructors
4) methods
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
John de Michele
Rancher
Joined: Mar 09, 2009
Posts: 600
|
|
I usually use the following order:
instance variables
final instance variables
static variables
final static variables
Constructors
Methods, in alphabetical order
John.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
John de Michele wrote:Methods, in alphabetical order
Why in alphabetical order? The Javadoc does that for you. I prefer to keep them together based on functionality. For instance, each getter and setter are put together, in the same order as the order of their matching fields; getter before setter.
|
 |
John de Michele
Rancher
Joined: Mar 09, 2009
Posts: 600
|
|
Rob Prime wrote:Why in alphabetical order? The Javadoc does that for you. I prefer to keep them together based on functionality. For instance, each getter and setter are put together, in the same order as the order of their matching fields; getter before setter.
Just a personal preference. I find it more aesthetically pleasing to have methods in alphabetical order. I can see the value of your method, but at an aesthetic level, it just feels disordered to me. For the record, all of my variables are organised in alphabetical order in each group, too .
John.
|
 |
 |
|
|
subject: By convention - are there for exemple first variables, second getters and setters and third methods?
|
|
|