Java OOP Principles

Enforces the four pillars of object-oriented programming in Java code.

Updated May 12, 2026
One-click install
npx skills add https://github.com/ZzZueszZ/claude-kit --skill java-oop-principles-zzzueszz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Java OOP Principles
Source: https://github.com/ZzZueszZ/claude-kit/tree/main/.claude/skills/java-oop
Command: npx skills add https://github.com/ZzZueszZ/claude-kit --skill java-oop-principles-zzzueszz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Java codebases often drift into poor object-oriented design: public fields, inheritance used only for code reuse, instanceof chains instead of polymorphism, and unclear abstraction boundaries. This Skill gives the AI a strict, example-driven rulebook so every class and method it writes or reviews follows the four OOP pillars. ## Core Features & Use Cases - Encapsulation enforcement: Requires private fields, defensive copies of collections, immutable objects with final fields, and Java Records for DTOs. - Inheritance discipline: Promotes composition over inheritance, final classes by default, and a maximum two-level inheritance depth. - Polymorphism and abstraction guidance: Mandates interface-based dependency injection, bans instanceof type-checking chains, and clarifies when to use abstract classes, interfaces, or sealed types (Java 17+). - Use Case: When asking the AI to build a Spring Boot order service, it will automatically design NotificationSender interfaces with Email and SMS implementations, inject them via constructor, and keep entity state encapsulated in a BaseEntity abstract class. ## Quick Start Ask the AI to write or review a Java class while following the Java OOP Principles skill, for example: create an OrderService that processes payments and sends notifications following the four OOP pillars.

Frequently Asked Questions about Java OOP Principles

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

FAQPage Schema
How do I apply encapsulation correctly in Java classes?▼

Encapsulation in Java requires declaring all fields private and exposing them only through getters or setters when truly needed. Return unmodifiable copies of collections, prefer final fields for immutability, and use Java Records for DTOs instead of hand-written getters.

When should I use composition instead of inheritance in Java?▼

Use composition whenever the relationship is not a clear IS-A relationship, such as an OrderService using a PaymentProcessor. Reserve inheritance for template method patterns, framework contracts, and tightly related subclasses, and mark classes final when they are not designed for extension.

Should I use an abstract class or an interface in Java?▼

Use an abstract class when subclasses share state or behavior, such as a BaseEntity with id and audit timestamps. Use an interface when defining a pure contract, and consider sealed interfaces in Java 17+ when the set of implementations is known in advance.

Why are instanceof checks considered bad practice in Java?▼

Instanceof chains violate polymorphism because every new type forces you to modify the checking method, breaking the open-closed principle. The correct approach is defining a common interface with implementations like EmailNotificationSender and SmsNotificationSender, then injecting the interface type.

Does this OOP guidance work with Spring Boot dependency injection?▼

Yes, the rules align directly with Spring Boot practices. Dependencies should be declared as interface types and injected via constructors, using @Qualifier to select among multiple implementations such as emailSender or smsSender beans.