Skip to content

QuizNot attempted

Liskov & interface segregation

A ReadOnlyList extends List but throws in add(). A <Avatar> requires a full user object when it only uses name and imageUrl. Which principles are broken?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Liskov Substitution, then Interface Segregation
  • A subtype that throws on add() can't be used wherever List is expected (Liskov Substitution), and forcing <Avatar> to take a whole user when it reads two fields makes it depend on what it doesn't use (Interface Segregation).
  • Not SRP/OCP: neither describes a broken subtype contract or a too-wide input.
  • Not DIP then Liskov: no abstraction is being injected, and the order is reversed.
  • Not DRY/KISS: nothing is duplicated or overcomplicated.
  • Pass { name, imageUrl }.