convention-solid-lsp

Enforce Liskov Substitution Principle contract preservation across inheritance hierarchies.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/sunLeee/optimization --skill convention-solid-lsp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: convention-solid-lsp
Source: https://github.com/sunLeee/optimization/tree/main/.claude/skills/reference/philosophy/solid/lsp
Command: npx skills add https://github.com/sunLeee/optimization --skill convention-solid-lsp

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

LSP requires that subtypes can replace base types without altering the correctness or behavior of consuming code. Violations occur when derived classes loosen or strengthen contracts, causing contract drift and runtime errors.

Core Features & Use Cases

  • Enforces contract preservation across inheritance hierarchies to maintain substitutability.
  • Provides guidance for safe extension using explicit interfaces, wrappers, and stable return contracts.
  • Use Case: refactor a base processor and a subclass so substituting the subclass does not require changes in client code.

Quick Start

Refactor a sample inheritance hierarchy to satisfy LSP safely and provide before/after code snippets.

Frequently Asked Questions about convention-solid-lsp

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

FAQPage Schema
What is the Liskov Substitution Principle and how does it affect inheritance hierarchies?

Liskov Substitution Principle (LSP) requires that subtypes remain fully substitutable for their base types without altering the correctness or behavior of consuming code. Violations occur when derived classes loosen or strengthen contracts, causing contract drift and runtime errors in inheritance-heavy codebases.

How do I refactor a base processor and subclass so substituting the subclass does not break client code?

To refactor a base processor for LSP compliance, enforce contract preservation across the inheritance hierarchy to maintain substitutability. Use explicit interfaces, wrappers, and stable return contracts to ensure the derived class does not require changes in the consuming client code.

When do I need to apply LSP-compliant refactoring to object-oriented designs?

You need to apply LSP-compliant refactoring when extending inheritance-heavy codebases, designing APIs, or modifying data loaders and processors. It is required when you must satisfy explicit contract maintenance and ensure extensions do not cause behavioral contract drift in consuming code.

What is the best way to decouple extensions in OOP design without strengthening base contracts?

The best way to decouple extensions without strengthening base contracts is by using explicit interfaces and wrappers. This approach preserves stable return types and maintains the original behavioral contracts, ensuring safe extension without violating LSP substitutability.

Why does substituting a subclass in my data loader cause runtime errors in the consuming code?

Substituting a subclass causes runtime errors because it violates LSP by loosening or strengthening the base class behavioral contracts, creating contract drift. The consuming code expects the original contract, so the altered subclass behavior breaks the application.

Can I use interfaces and wrappers to preserve return contracts during inheritance refactoring?

Yes, you can use interfaces and wrappers to decouple extensions and preserve return contracts during inheritance refactoring. This technique maintains explicit contract preservation across the hierarchy, ensuring subtypes remain safely substitutable for their base types.