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:

  1. Public constants.
  2. Private static or class-level variables.
  3. Private instance variables (fields).
  4. Public functions.
  5. 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.

Installs
1
First Seen
1 day ago