Use when deciding between inheritance and composition in object-oriented design. Use when creating class hierarchies or composing objects from smaller components.
View on GitHubTheBushidoCollective/han
jutsu-oop
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-oop/skills/oop-inheritance-composition/SKILL.md -a claude-code --skill oop-inheritance-compositionInstallation paths:
.claude/skills/oop-inheritance-composition/# OOP Inheritance and Composition
Master inheritance and composition to build flexible, maintainable object-oriented systems. This skill focuses on understanding when to use inheritance versus composition and how to apply each effectively.
## Inheritance Fundamentals
### Basic Inheritance in Java
```java
// Base class with common behavior
public abstract class Vehicle {
private String brand;
private String model;
private int year;
protected double currentSpeed;
protected Vehicle(String brand, String model, int year) {
this.brand = brand;
this.model = model;
this.year = year;
this.currentSpeed = 0.0;
}
// Template method pattern
public final void start() {
performSafetyCheck();
startEngine();
System.out.println(brand + " " + model + " started");
}
// Hook method for subclasses
protected void performSafetyCheck() {
System.out.println("Performing basic safety check");
}
// Abstract method - must be implemented
protected abstract void startEngine();
public void accelerate(double speed) {
currentSpeed += speed;
System.out.println("Current speed: " + currentSpeed);
}
public void brake(double reduction) {
currentSpeed = Math.max(0, currentSpeed - reduction);
System.out.println("Current speed: " + currentSpeed);
}
// Getters
public String getBrand() { return brand; }
public String getModel() { return model; }
public int getYear() { return year; }
public double getCurrentSpeed() { return currentSpeed; }
}
// Concrete implementation
public class Car extends Vehicle {
private int numberOfDoors;
private boolean isSunroofOpen;
public Car(String brand, String model, int year, int numberOfDoors) {
super(brand, model, year);
this.numberOfDoors = numberOfDoors;
this.isSunroofOpen = false;
}
@Override
protected void startEngine() {