SpinTheMic
Pro

Interview practice question

Subclass breaks code that uses the parent

Backend Engineering · OOP and Design Patterns · Beginner

A teammate created a ReadOnlyRepository that extends Repository and throws an exception in save(). Code that accepts Repository now crashes. What is wrong?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Liskov substitution violation.
  • Subclass weakens contract.
  • Split interfaces: Reader and Writer.
  • Depend on the smallest needed interface.
  • Inheritance not appropriate.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics