java-readable-code
Java Readable Code
Default Style
- Prefer small focused classes, explicit responsibilities, intention-revealing names, readable control flow, and minimal incidental complexity.
- Prefer GoF design patterns where they fit naturally.
- Avoid broad utility classes that mix unrelated concerns such as creation, mapping, conversion, logging, and key formatting; extract cohesive collaborators with narrow names instead.
- Avoid passing non-trivial method calls directly as arguments when an intermediate variable would clarify intent. Name semantically important intermediate results.
- Prefer simple, common words that non-native speakers can read without looking them up.
Orchestration And Local Operations
Keep orchestration at one level of abstraction. Extract a complete meaningful operation, including its related checks, branching, and construction, instead of adding small predicates that leave the caller coordinating the same details.
Prefer a private method when an operation belongs to one owner. Introduce a collaborator when an independent responsibility, actual reuse, complexity, or composition benefit justifies it. Returning an object does not by itself require a factory class. Leave ordinary expressions inline when extraction would only add indirection.
For before/after Java examples, read orchestration and composition when refactoring complex orchestration or result construction. Local extraction must preserve input contracts and exception ownership under java-request-validation and java-logging-exceptions.