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.
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
- What is a design pattern, and why are they useful?
- How do you implement a Singleton, and why is it often considered an anti-pattern?
- What is the difference between dependency inversion, dependency injection and inversion of control?
- Why is composition often preferred over inheritance?
- What is dependency injection, and what forms does it take?
- Explain the Factory Method pattern and how it differs from a simple factory.
- What problem does the Builder pattern solve? Show an example.
- What is the Adapter pattern? Give an example.