DSA Factory
Free SOLID and design smells lessonsSOLID and design smells · Stage 1 · Substitution and dependencies · Step 1

Liskov substitution

What it takes for a subclass to be safely used wherever its parent is expected, and the behavioural rules beyond the type signature. About 13 minutes.

Quick check

A subclass overrides a method to throw UnsupportedOperationException. What does that usually indicate?

  1. AA Liskov violation: the inheritance does not model a true is-a
  2. BA sound way to restrict a subclass
  3. CA performance optimisation
Show the answer

A Liskov violation: the inheritance does not model a true is-a. Callers of the parent expect the operation to work.

Lock it in

4 questions on this idea

Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.

Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve