SOLID Principles Reference

SOLID, DRY, KISS, YAGNI and more — each principle's definition, the anti-pattern it prevents, and its code smell

Searchable software design principle reference: the five SOLID principles plus DRY, KISS, YAGNI, Separation of Concerns and the Law of Demeter, each with a definition, the anti-pattern it prevents, and the smell that signals you broke it.

What does SOLID stand for?

SOLID is five object-oriented design principles: Single Responsibility (one reason to change per class), Open/Closed (open to extension, closed to modification), Liskov Substitution (subtypes substitutable for base types), Interface Segregation (no fat interfaces), and Dependency Inversion (depend on abstractions, not concretions). Robert C. Martin popularized the acronym.

SOLID and its companions DRY, KISS and YAGNI are the principles that keep code maintainable as it grows. They do not tell you what to build — they tell you how to structure it so change stays cheap. This reference gives each principle’s definition, the anti-pattern it guards against, and the smell that reveals a violation.

How it works

The five SOLID principles target object-oriented structure:

  • S — Single Responsibility: one reason to change per class.
  • O — Open/Closed: extend behavior with new code, don’t edit tested code.
  • L — Liskov Substitution: subtypes must honor their base type’s contract.
  • I — Interface Segregation: many small interfaces beat one fat one.
  • D — Dependency Inversion: depend on abstractions, not concretions.

The related principles restrain complexity: DRY (one source of truth), KISS (simplest design that works), YAGNI (don’t build it until needed), plus Separation of Concerns and the Law of Demeter.

Example

A ReportService that formats HTML, runs SQL, and sends email violates Single Responsibility — three unrelated reasons to change. Splitting it into a formatter, a repository, and a mailer, each behind an interface the service depends on, also satisfies Dependency Inversion and makes the service unit testable without a real database or SMTP server.

Notes

  • A telling smell for SRP is a class name containing “And” or a vague “Manager”.
  • An Open/Closed smell is a growing switch you must edit for every new type; replacing it with polymorphism or Strategy fixes both.
  • Interface Segregation is violated when implementers stub methods with empty bodies or “not implemented” throws.
  • Apply them to diagnose real pain, not as universal quotas — over-applying DIP or ISP creates indirection that KISS and YAGNI exist to prevent.