I'll Be Backend
Principles

Liskov Substitution Principle: Fix a Subtype That Breaks Callers

The Liskov Substitution Principle says code that works with a base type must keep working with any subtype of it: a subclass keeps its parent's contract. These lessons take a payment hierarchy where a new gift card cannot refund, so a caller crashes and then has to check the class, and move refund into its own interface so every payment method can stand in for its base type.

Pick your language

When to use it

Use it when

A subclass overrides a method only to throw, to do nothing, or so that its callers need a special case.

Skip it when

The subtype can keep the contract with real behavior. If gift cards got store credit back, GiftCard would implement refund that way.

Spot it by

A caller that checks the exact class with instanceof, or an override that throws UnsupportedOperationException.