I prefer grouping the methods by functionality. Generally I'll have a public method, followed by any private methods used by the previous public method. Then another public method, followed by private methods which are called by that public method. And so on. Or I might have several public methods in a row, followed by several private methods which are used by all of the preceding group of public methods. These methods may be static or not; that doesn't affect the order much, for me. The goal is to try to place methods near to the methods they call, or that call them. Usually there is no perfect solution to this, but I find it's easier to read if I try to get related methods close to each other.
Note that this style is also recommended in Sun's Coding Conventions. You can take these or leave them; in other contexts I have no problem deviating from these conventions if I think it's worthwhile. But here I fully agree with their recommendation.
Many IDEs allow you to display a list of method names in alphabetical order, and/or grouped by access level. So if you want this sort of list, you can obtain one easily enough, while leaving the source file itself in a different order (grouped by functionality, preferably). As EFH notes, sorting the file manually is probably not worth the effort. However there are code reformatting tools out there which can be used to reformat the source automatically, including putting the methods in a particular order if you think that's desireable. I don't recommend it, but you can. [ March 01, 2006: Message edited by: Jim Yingst ]
I use public/protected/private but also group them as type(get, set, ect). I will deviate like in a tree that searches recursivly, I will put the public search method and the private recursive method together.
I think the main thing is to do it logically, and be consistant, and only break that convention when that convention doesn't make sense. As opposed to breaking it if something is slightly better.
I go with Jim on putting functionality together. I come from many years of structured stuff before object stuff and I still find "making code express what it's doing" is a lot like "functional decomposition" some times. If a method calls three other methods to get the job done I'll put them in the order they're called. It makes an imaginary calling tree within the class. And it doesn't work very well when methods are reused and called from several places. Then I just move them down somewhere.
Getters and Setters are annoying noise. They go right to the bottom.
F3 in Eclipse is so cool the order matters less all the time.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I prefer classes that are so small that method ordering basically is a non-issue.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Our first order of business must be this tiny ad:
a bit of art, as a gift, that will fit in a stocking