- SOLID principles (wikipedia) are the design principles that enable us manage most of the software design problems.
- The term SOLID is an acronym for five design principles intended to make software designs more understandable, flexible and maintainable.
- The principles are a subset of many principles promoted by Robert C. Martin (aka Uncle Bob).
- The SOLID acronym was first introduced by Michael Feathers.
- S : Single Responsibility Principle (SRP).
- O : Open closed Principle (OCP).
- L : Liskov substitution Principle (LSP).
- I : Interface Segregation Principle (ISP).
- D : Dependency Inversion Principle (DIP).
- Robert C. Martin expresses the principle as: "A class should have only one reason to change.".
- Every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class.
- Software entities should be open for extension, but closed for modification.
- The design and writing of the code should be done in a way that new functionality should be added with minimum changes in the existing code.
- The design should be done in a way to allow the adding of new functionality as new classes, keeping as much as possible existing code unchanged.
- Introduced by Barbara Liskov, it states that "objects in a program should be replaceable with instances of their sub-types without altering the correctness of that program".
- If a program module is using a base class, then the reference to the base class can be replaced with a derived class without affecting the functionality of the program module.
- We can also state that derived types must be substitutable for their base types.
- Many client-specific interfaces are better than one general-purpose interface.
- We should not enforce clients to implement interfaces that they don't use. Instead of creating one big interface we can break down it to smaller interfaces.
- One should depend upon abstractions, not concretions.
- Abstractions should not depend on the details whereas the details should depend on abstractions.
- High-level modules should not depend on low level modules.
- End up with tight or strong coupling of the code with many other modules/applications.
- Tight coupling causes time to implement any new requirement, features or any bug fixes and some times it creates unknown issues.
- End up with a code which is not testable.
- End up with duplication of code.
- End up creating new bugs by fixing another bug.
- End up with many unknown issues in the application development cycle.
- Achieve reduction in complexity of code.
- Increase readability, extensibility and maintenance.
- Reduce error and implement reusability.
- Achieve better testability.
- Reduce tight coupling.