• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Order of methods

 
Akash Singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is Java standard for ordering methods, Is this based on access scope(public, proteced, friendly, private) or based on functionalty ?

Below i am giving method signatures of given Data class :

These methods are not ordered based on access scope, and also not based on functionalty (close, finalize should be last method).
Should i change order or not ? If changed , how these methods should be ordered ?
Regards,
Akash
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Akash,
And to think that we have just been discussing whether or not we have to use Sun Code Conventions for the JavaTM Programming Language
The Class and Interface Declarations section of that tells us:

These methods should be grouped by functionality rather than by scope or accessibility. For example, a private class method can be in between two public instance methods. The goal is to make reading and understanding the code easier.

Regards, Andrew
 
Akash Singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Very Much, Andrew.
Regards,
Akash
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic