S.O.L.I.D Principles
S.O.L.I.D Principles in Object-Oriented Design
S.O.L.I.D is an acronym representing five principles of good software design in object-oriented programming. These principles help in creating maintainable, scalable, and robust code.
S - Single Responsibility Principle (SRP)
- A class should have only one reason to change.
- Each class should focus on a single responsibility, making it easier to understand, maintain, and extend.
O - Open/Closed Principle (OCP)
- Software entities (classes, modules, functions) should be open for extension but closed for modification.
- New functionality should be added by extending existing code, not by changing it.
L - Liskov Substitution Principle (LSP)
- Subtypes must be substitutable for their base types without affecting the correctness of the program.
- Objects of a derived class should be able to replace objects of the base class without disrupting the behavior of the program.
I - Interface Segregation Principle (ISP)
- Clients should not be forced to depend on interfaces they do not use.
- Keep interfaces specific to the needs of the client to avoid unnecessary dependencies.
D - 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.