java-solid-principles

Reviews Java classes for SOLID principle violations and provides refactored solutions.

Updated Apr 20, 2020
One-click install
npx skills add https://github.com/UnterrainerInformatik/java-rdb-utils --skill java-solid-principles-unterrainerinformatik
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: java-solid-principles
Source: https://github.com/UnterrainerInformatik/java-rdb-utils/tree/main/.agents/skills/java-solid-principles
Command: npx skills add https://github.com/UnterrainerInformatik/java-rdb-utils --skill java-solid-principles-unterrainerinformatik

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Java codebases often accumulate design problems like god classes, fat interfaces, and hard-coded dependencies that make code hard to test, extend, and maintain. This Skill provides a structured checklist to detect violations of the five SOLID principles and shows concrete refactored solutions for each. ## Core Features & Use Cases - Violation Detection: Identifies Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion violations using concrete detection patterns like type-switching, instanceof checks, and empty method implementations. - Refactored Java Examples: Each principle includes a violation example followed by a corrected implementation using patterns like Strategy, Dependency Injection, and interface segregation. - Review Checklist: Provides quick-check questions per principle for systematic code reviews, including Spring-based dependency injection examples. - Use Case: Ask it to review a UserService class, and it identifies an SRP violation where validation, persistence, email, and audit logic are mixed, then suggests extracting each concern into dedicated classes. ## Quick Start Review this UserService class for SOLID principle violations and suggest refactorings.

Frequently Asked Questions about java-solid-principles

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I check a Java class for SOLID violations?▼

Review the class against five questions: does it have one reason to change (SRP), can you extend it without modification (OCP), are subtypes substitutable (LSP), are implementations forced to implement unused methods (ISP), and does it depend on abstractions (DIP). Detection signals include many unrelated imports, if/else type switching, instanceof checks, and empty method implementations.

How to fix a Single Responsibility Principle violation in Java?▼

Extract each distinct concern into its own class, such as splitting validation, persistence, notification, and audit logic out of a service class. The original class then coordinates these collaborators through constructor injection, making each concern independently testable.

Why shouldn't Square extend Rectangle in Java?▼

Square extending Rectangle violates the Liskov Substitution Principle because setting width on a Square unexpectedly changes height, breaking the parent class contract. Code expecting Rectangle behavior, like area calculations after independent width and height changes, fails when given a Square.

Does Dependency Inversion work with Spring Framework?▼

Yes, Spring supports Dependency Inversion through constructor injection of interfaces. Define repository and notification interfaces, annotate implementations with @Repository or @Component, and use @Profile to swap implementations like SMTP versus mock email senders per environment.

What are signs of a fat interface violating Interface Segregation?▼

Signs include implementations with empty methods or UnsupportedOperationException, interfaces with ten or more methods, and clients using completely different method subsets. The fix is splitting the interface into smaller role-specific interfaces that classes combine as needed.