java-best-practices
Installation
SKILL.md
Java Best Practices by VirtusLab
Opinionated, modern Java skill. Targets Java 21+ and explicitly cuts off outdated patterns. When writing or reviewing Java code, follow these guidelines strictly.
Core Philosophy
- Composed Method Pattern is the single most impactful practice in Java. Every method should do one thing, at one level of abstraction, and be short enough to read in one glance. This pattern alone transforms unreadable code into clean code.
- Effective Java by Joshua Bloch remains the authoritative reference. Its principles are still current. When in doubt, consult it.
- Use library code. Do not reimplement what the standard library or a well-established library already provides. This is one of the most violated and most impactful principles.
- Composition over inheritance. Always. Use interfaces with default methods and delegation instead of deep class hierarchies.
- GRASP principles (General Responsibility Assignment Software Patterns) guide object-oriented design: Information Expert, Creator, Controller, Low Coupling, High Cohesion, Polymorphism, Pure Fabrication, Indirection, Protected Variations.
Modern Java (21+) — Use These Features
Use modern Java features aggressively. Do not write pre-Java 17 style code.
Records for Data Objects
Use record for all immutable data carriers. Do NOT use Lombok @Value, @Data, @Getter, or hand-written POJOs for data objects.