SOLID is an acronym for five object-oriented design principles that help create maintainable, scalable, and testable software.
The five principles:
- S — Single Responsibility Principle (SRP): A class should have only one reason to change, meaning it should have only one job or responsibility.
- O — Open/Closed Principle (OCP): Software entities should be open for extension but closed for modification. New behavior should be added by extending, not altering existing code.
- L — Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types without altering correctness. A derived class should not break the behavior expected by the base class contract.
- I — Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use. Prefer many small, specific interfaces over one large general-purpose interface.
- D — Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules; both should depend on abstractions. Depend on interfaces/abstractions, not concrete implementations.
Common follow-ups: Give a real-world code example violating and then fixing each principle; explain how SOLID relates to design patterns like Strategy, Factory, or Decorator; discuss trade-offs (over-engineering small projects).
This question tests conceptual depth as well as practical application — interviewers often ask candidates to identify SOLID violations in a given code snippet or design scenario.