Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

By convention - are there for exemple first variables, second getters and setters and third methods?

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By convention - are there for exemple first variables, second getters and setters and third methods into the class?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean the order they are in the source file ?
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually use the following order:
1) static fields
2) instance fields
3) constructors
4) methods
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic