SOLID is an acronym for five object-oriented design principles introduced by Robert C. Martin (Uncle Bob) that guide developers toward creating maintainable, scalable, and flexible software systems. These principles address dependency management and separation of concerns, helping to reduce coupling, increase cohesion, and make code easier to test, modify, and extend. While rooted in object-oriented programming, SOLID has proven relevant across paradigms β from microservices architecture to React components to Rust traits. Understanding when and how to apply these principles pragmatically, without over-engineering, is key to writing professional-grade code that withstands change.
What This Cheat Sheet Covers
This topic spans 14 focused tables and 108 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core SOLID Principles
Each principle attacks a different failure mode in software design: SRP stops class sprawl, OCP prevents regression-causing rewrites, LSP enforces reliable inheritance, ISP shrinks bloated interfaces, and DIP inverts rigid dependencies. Together they form a coherent strategy for keeping codebases adaptable.
| Principle | Example | Description |
|---|---|---|
class User { login() {...} }class UserRepository { save() {...} } | β’ A class should have one and only one reason to change β’ responsible to one actor (one business function or stakeholder). | |
interface Shape { area(): number }class Circle implements Shape {...} | β’ Modules should be open for extension but closed for modification β’ add features via new code, not by changing existing tested code. | |
Rectangle r = new Square();r.setWidth(5); r.setHeight(10); | β’ Subtypes must be substitutable for their base types without altering program correctness β’ subclasses must honor parent contracts and not surprise callers. |