Robert C. Martin’s Principle Collection (including SOLID)

0
921

Robert C. Martin collected ten principles dealing with object-oriented design. The first five of them—the so-called SOLID principles— deal with the design of classes:

  1. Single Responsibility Principle (SRP)
  2. Open-Closed Principle (OCP)
  3. Liskov Substitution Principle (LSP)
  4. Interface Segregation Principle (ISP)
  5. Dependency Inversion Principle (DIP)

1. Single Responsibility Principle (SRP)

Every class should have only one responsibility or reason to change. This ensures that a class focuses on a single function or purpose, making it easier to maintain and understand.

2. Open-Closed Principle (OCP)

Software entities (classes, modules, functions) should be open for extension but closed for modification. This means you can add new functionality without altering existing code, reducing the risk of introducing bugs.

3. Liskov Substitution Principle (LSP)

Objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program. This ensures that derived classes extend functionality without altering expected behavior.

4. Interface Segregation Principle (ISP)

Clients should not be forced to depend on interfaces they do not use. It’s better to have smaller, more specific interfaces tailored to individual client needs rather than a large, general-purpose interface.

5. Dependency Inversion Principle (DIP)

High-level modules should not depend on low-level modules. Both should depend on abstractions. Additionally, abstractions should not depend on details; details should depend on abstractions. This encourages decoupling and improves flexibility.

Then there are three principles of package cohesion:

The last three principles deal with package coupling:

Origin