oop-inheritance-composition

Guide developers in choosing between inheritance and composition for class hierarchies.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill oop-inheritance-composition
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: oop-inheritance-composition
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-oop/skills/oop-inheritance-composition
Command: npx skills add https://github.com/TheBushidoCollective/han --skill oop-inheritance-composition

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill teaches when to use inheritance vs composition in OO design.

Core Features & Use Cases

  • Inheritance fundamentals: Basic and template method usage.
  • Composition patterns: Delegation and mixins.
  • Practical guidance: When to prefer each approach.

Quick Start

Build a small class hierarchy and a composable module to compare approaches.

Frequently Asked Questions about oop-inheritance-composition

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

FAQPage Schema
When should I use inheritance vs composition in object-oriented design?

Inheritance creates tight hierarchies best for shared behavior and polymorphism; composition uses delegation for flexibility and code reuse. Choose inheritance for true "is-a" relationships and composition for "has-a" relationships to build maintainable, testable systems that adapt to change.

How do I decide between inheritance and composition for my class hierarchy?

Evaluate whether subclasses represent true specializations (inheritance) or whether behavior can be delegated to contained objects (composition). Apply template method patterns for shared logic in hierarchies, and use mixins or delegation for cross-cutting concerns. Document tradeoffs to ensure extensibility.

What are the limitations of deep inheritance hierarchies?

Deep inheritance hierarchies create brittle systems where changes to parent classes cascade unpredictably, reduce flexibility, and complicate testing. Composition avoids these constraints by letting you swap implementations at runtime and keep classes loosely coupled.

Can I use both inheritance and composition together in the same system?

Yes. Use inheritance for abstract base classes and template methods that define shared contracts, then compose concrete implementations to handle specific behavior. This hybrid approach balances polymorphism benefits with composition's flexibility and testability.

How do composition patterns like delegation and mixins work across Java and Python?

Delegation wraps objects and forwards method calls to composed instances; mixins in Python add behavior through multiple inheritance or composition. Both patterns enable code reuse and system extensibility without rigid class hierarchies, supporting polymorphism through interface contracts.

What design patterns help implement composition effectively?

Decorator, Strategy, and Observer patterns encapsulate behavior in composed objects. Abstract versus concrete implementations define boundaries; hooks in template methods coordinate inheritance and composition. These patterns create maintainable systems where behavior is swappable and testable.