Skip to content

QuizNot attempted

Which SOLID principle?

A <UserCard> fetches the user, formats dates, tracks analytics and renders the card. Which principle does it violate most?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Single Responsibility
  • The component has four reasons to change (data fetching, date formatting, analytics, markup), which is the definition of violating Single Responsibility
  • split it into useUser, a formatter, an analytics hook and a presentational card.
  • Not Liskov: there is no subtype being substituted.
  • Not Interface Segregation: that is about consumers depending on more than they use.
  • Not Open/Closed: that is about extending without editing
  • it may also suffer, but SRP is the main problem.