policy - Java: place of constructors, static methods, public methods, private? -


this question has answer here:

i have come question: preferred way of placing methods? mean, should first declare static methods, constructors, public methods, protected, private, etc? there kind of convention, guess places fields (instance variables) on top of code. there same policy methods?

i guess depends on language use. java?

this opinion based, google java style doc puts nicely:

the ordering of members of class can have great effect on learnability, there no single correct recipe how it. different classes may order members differently.

what important each class order members in logical order, maintainer explain if asked. example, new methods not habitually added end of class, yield "chronological date added" ordering, not logical ordering.

https://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s3.4.2-class-member-ordering

most of code see in open source world uses variation of

  • static fields
  • instance fields
  • constructors
  • methods (instance , static)
  • anonymous classes

Comments