Principles of SOLID
Open-Closed Principle (O.C.P)
- "Objects or entities should be open for extension, but closed for modification." - That is, such an entity can allow its behavior to be modified without altering its source code."
Benefits of S.R.P
- Better cohesion - Improved readability - Easier to debug/test (fewer test cases) - Lower coupling - Improved usability (separation of concerns)
Single-Responsibility Principle (S.R.P)
- Every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. - "A class should have one and only one reason to change, meaning that a class should have only one job."
Why use S.O.L.I.D?
Makes code: - More maintainable - Easier to extend without breaking existing functionality - Easier to read and understand - Less rigid (difficult to change) - Less fragile (prone to break in many, often unrelated places) Less immobile (more reusable)
What is S.O.L.I.D?
S - Single-responsibility principle O - Open-closed principle L - Liskov substitution principle I - Interface segregation principle D - Dependency Inversion Principle