clean-code-classes
Installation
SKILL.md
Classes
Functions are the first level of organization. Classes, or modules in non-OO languages, are the next one up. The same values apply: small, focused and easy to change.
Class organization
Follow the language's convention. A sensible default (the Java convention) is:
- Public constants.
- Private static or class-level variables.
- Private instance variables (fields).
- Public functions.
- Private helpers, placed right after the public function that uses them (stepdown rule).
Public fields are rarely justified.
Encapsulation. Keep fields and helpers private by default. Loosening visibility so a test can reach something is acceptable as a last resort, since tests rule. But first look for a way to keep things private, such as testing through the public API or extracting the helper into its own class.