Separate public and private members
It's a common practice to separate the members of a class according to their scope (private, package-private, protected, public).
It's a matter of some debate, however, which should come first.
- is advocated by Oracle's coding conventions.
- is significantly more popular among Java programmers, and is thus expected by many readers.
- emphasizes implementation details over exported API.
- it agrees with the idea that the exported API is an order of magnitude more important than the implementation - if the exported API should almost always be read first, then clearly it should appear first.
- it agrees with Steve McConnell's Fundamental Theorem of Formatting: "good visual layout shows the logical structure of a program". Here, placing public members first puts a clear visual emphass on the exported API, and relegates implementation details to the bottom.
- Joshua Bloch once stated that the Oracle coding conventions are not used or maintained by Oracle, and shouldn't be taken too seriously.
- public-first is popular among C++ programmers; for instance, the popular books Design Patterns and Effective C++ always follow the public-first style. Over time, the C++ community has apparently come to favor this style as more effective. Is the Java community ignoring a lesson already learned elsewhere?
See Also :
Would you use this technique?