The SOLID principles where defined by Robert C. Martin (“Uncle Bob”) since the mid-1990. In his canonical book Agile Software Development, Principles, Patterns, and Practice (2003), he compiles his previous articles and describes them in detail. They are general principles for object-oriented solutions, but with concrete implications in class and types definitions.
Paradoxically, many programmers, self-called object-oriented programmers, doesn’t know about them or know them very superficially. It’s particularly strange that the Agile environment of today —SCRUM oriented, mainly— doesn’t encourage too much its knowledge, coming from one of the first books about the movement.
Let’s review them with some simple examples:
- Single-Responsibility principle (SRP)
- “A class should have only one reason to change.”
- Open-Close principle (OCP)
- “Software entities should be open for extension, but closed for modification.”
- Liskov-Substitution principle (LSP)
- “Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.”
- Interface-Segregation principle (ISP)
- “No client should be forced to depend on methods it does not use.”
- Dependency-Inversion principle (DIP)
- High-level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Details should depend on abstractions.
Those principles are the credo for good practices in programming based on objects orientation. But as many programmers introduced to them, it’s difficult to understand them without concrete examples.
In the following post links I will describe them in more detail, showing some simple examples for illustration.