oop-polymorphism

Design polymorphic systems using interfaces and abstract classes for runtime substitution.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Use this skill when designing object-oriented systems that benefit from interchangeable implementations behind a common interface. It helps you decouple callers from concrete classes and enables runtime substitution of components.

Core Features & Use Cases

  • Interface-based polymorphism: Define a single interface and multiple implementations to swap behavior without changing client code.
  • Extensible architectures: Add new implementations (e.g., CreditCard, PayPal, BankTransfer) without touching existing usage sites.
  • Use Case: Build a payment processor that can try multiple methods and select the first valid option at runtime.

Quick Start

Create a PaymentMethod interface with process() and isValid() methods, implement CreditCard, PayPal, and BankTransfer, and wire them into a PaymentProcessor that iterates available methods until one succeeds.

Frequently Asked Questions about oop-polymorphism

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

FAQPage Schema
How do I design a system where I can swap implementations without changing client code?

Interface-based polymorphism lets you define a common contract (interface) with multiple implementations that clients use interchangeably. At runtime, you substitute different implementations—such as CreditCard, PayPal, or BankTransfer in a payment processor—without modifying the code that calls them, enabling flexible, extensible architectures.

What's the difference between using interfaces and concrete classes for interchangeable components?

Interfaces define a contract that multiple implementations fulfill, decoupling callers from concrete classes and enabling runtime substitution. Concrete classes bind behavior directly, requiring code changes to swap implementations. Polymorphism through interfaces supports extensibility; concrete classes create tight coupling and make testing harder.

How do I implement runtime substitution to select the first valid payment method?

Create a PaymentMethod interface with process() and isValid() methods, implement concrete classes for each method (CreditCard, PayPal, BankTransfer), and wire them into a PaymentProcessor that iterates through available methods, calling isValid() until one succeeds, then executes process() on that implementation.

Can I add new payment methods to an existing system without modifying existing code?

Yes. With interface-based polymorphism, you create new implementations of the PaymentMethod interface—such as ApplePay or cryptocurrency handlers—and register them with the PaymentProcessor. Existing code remains unchanged because it depends on the interface contract, not concrete classes.

When should I use abstract classes instead of interfaces for polymorphic behavior?

Use abstract classes when implementations share common code, state, or initialization logic. Use interfaces when defining a pure contract across unrelated implementations. Both support polymorphic behavior; abstract classes work better for shared implementation details, interfaces for looser coupling across diverse types.

How does polymorphism support testable, extensible architectures?

Polymorphism through interfaces lets you inject mock implementations during testing without changing production code, and add new behaviors by implementing the interface rather than modifying existing classes. This isolates changes, reduces regression risk, and makes systems easier to extend and test.