Back to Skills

oop-inheritance-composition

verified

Use when deciding between inheritance and composition in object-oriented design. Use when creating class hierarchies or composing objects from smaller components.

View on GitHub

Marketplace

han

TheBushidoCollective/han

Plugin

jutsu-oop

Technique

Repository

TheBushidoCollective/han
60stars

jutsu/jutsu-oop/skills/oop-inheritance-composition/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
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-composition

Installation paths:

Claude
.claude/skills/oop-inheritance-composition/
Powered by add-skill CLI

Instructions

# 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() {
      

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
28630 chars