Design Patterns interview question · Most asked

Explain the SOLID principles.

Summary

SOLID is five object-oriented design principles: Single Responsibility (one reason to change), Open/Closed (extend without modifying), Liskov Substitution (subtypes keep the parent's promises), Interface Segregation (small, focused interfaces) and Dependency Inversion (depend on abstractions, not concrete details).

Longer Answer

  • S: a class should answer to one group of people, so changes for different reasons don't collide.
  • O: add behaviour by adding code (a new class or strategy), not by editing code that already works.
  • L: any code that works with a parent type must work with a subtype without surprises.
  • I: clients shouldn't depend on methods they don't use; split large interfaces.
  • D: high-level policy and low-level details both depend on abstractions, which the high-level side owns. Dependencies are passed in.

They are guidelines that make code easier to test and change. Applied mechanically, they can produce too many tiny classes; use them where changes actually collide.

Key Points

  • Five principles for maintainable OO design.
  • Each one reduces the cost of a specific kind of change.
  • DIP is the principle; DI is the technique.
  • Guidelines, not laws: apply where change happens.

Deep dive: Design Patterns, Explained Simply: SOLID, Part 1

Explanation

What interviewers look for

A concise, correct definition of each letter with an example, plus awareness of over-application.

Follow-up questions

  • Which principle do you see violated most often?
  • Give an example of an LSP violation.

More most-asked Design Patterns questions

← All Design Patterns questions