In conclusion
I have argued in this article that four common Java idioms should be modified. The ultimate justification for such changes is that they will make code demonstrably easier to read, understand, and use -- and, in the process, they will exhibit more compassion for the mental experience of the reader. In the case of immutability and packaging style, they will also nudge you in the direction of improved design.
In summary, I suggest that the following idioms should be favored as the preferred style:
- Use a naming convention to distinguish three kinds of data, not two: local variables, fields, and method arguments.
- Prefer the package-by-feature style over package-by-layer.
- Prefer immutable objects over JavaBeans.
- Order items in a class in terms of decreasing scope, with private items appearing last.