Single-responsibility principle (SRP) states that "[t]here should never be more than one reason for a class to change."[2] In other words, every class should have only one responsibility.[3]
Importance
Maintainability: When classes have a single, well-defined responsibility, they're easier to understand and modify.
Testability: It's easier to write unit tests for classes with a single focus.
Flexibility: Changes to one responsibility don't affect unrelated parts of the system.[3]
Open–closed principle
Open–closed principle (OCP) states that "[s]oftware entities ... should be open for extension, but closed for modification."[4]
Importance
Extensibility: New features can be added without modifying existing code.
Stability: Reduces the risk of introducing bugs when making changes.
Flexibility: Adapts to changing requirements more easily.
Loose coupling: Reduces dependencies between modules, making the code more flexible and easier to test.
Flexibility: Enables changes to implementations without affecting clients.
Maintainability: Makes code easier to understand and modify.[8][7]
Origin
Software engineer and instructor, Robert C. Martin,[9][10][1] introduced the collection of principles in his 2000 paper Design Principles and Design Patterns about software rot.[10][7]: 2–3 The SOLID acronym was coined around 2004 by Michael Feathers.[11]
^Martin, Robert C."Principles Of OOD". ButUncleBob.com. Archived from the original on Sep 10, 2014. Retrieved 2014-07-17.. (Note the reference to "the first five principles", although the acronym is not used in this article.) Dates back to at least 2003.
^ abMartin, Robert C. (13 Feb 2009). "Getting a SOLID start". Uncle Bob Consulting LLC (Google Sites). Archived from the original on Sep 17, 2013. Retrieved 2013-08-19.