Five rules of object-oriented design set out by Robert Martin: he analysed the OCP, LSP, DIP and ISP principles in his 2000 article “Design Principles and Design Patterns”, and formulated SRP in the late 1990s. Each rule fights code “rot” — a state where a small change triggers a cascade of changes in other modules, and the code becomes ever more expensive to maintain.
The five principles
| Abbreviation | Principle | Essence |
|---|---|---|
| SRP | Single Responsibility Principle | a module has one reason to change — one responsibility to one group of users |
| OCP | Open-Closed Principle | behaviour is extended by adding new code rather than rewriting working code; formulated by Bertrand Meyer in 1988 |
| LSP | Liskov Substitution Principle | a subtype works anywhere the base type is expected without breaking the program; the idea was proposed by Barbara Liskov in 1987 |
| ISP | Interface Segregation Principle | several narrow interfaces are better than one wide one, so that clients do not depend on methods they do not need |
| DIP | Dependency Inversion Principle | code depends on abstractions, not on concrete classes: “depend on abstractions, not on concretions” |
The SOLID acronym is made up of the first letters of the principle names. Martin clarified that a single responsibility is not “one line of code” but one group of people asking for changes: if a class calculates salaries and builds reports, a change to the calculation may accidentally break the report — and both sides end up unhappy.
Example: dependency inversion
class InvoiceGateway(Protocol): def get(self, invoice_id: int) -> Invoice: ... class PdfExporter: def __init__(self, gateway: InvoiceGateway) -> None: self.gateway = gateway # depends on the abstraction, not on the database class Business rules import neither the database class nor the HTTP client — an interface is enough for them. In production an implementation backed by PostgreSQL arrives; in tests, a fake built from a dictionary. This is how DIP and SRP work together: report logic changes independently of storage. Clean and hexagonal architectures build on DIP, with the core unaware of the details.
How to apply them without going overboard
The principles concern classes and modules inside a component, not boundaries between components: cohesion and coupling govern the ties between parts of a system. Do not carve out interfaces for every client without need. Introduce abstractions where a second behaviour is genuinely foreseen, not “just in case”.
Sources
the term is written from these pages- Robert C. Martin — Design Principles and Design Patterns (2000)web.archive.org/web/20041209001203/http://www.objectmentor.com/resources/articles/Principles_and_Patterns.PDF(opens in a new tab)
- Robert C. Martin — The Single Responsibility Principle (2014)blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html(opens in a new tab)
Verified 8 Nov