Title | OOP B Week 8 SRP & OCP - Dr. Mark Doughty |
---|---|
Author | Josh Southern |
Course | Object-Oriented Programming |
Institution | University of Lincoln |
Pages | 1 |
File Size | 42 KB |
File Type | |
Total Views | 128 |
Dr. Mark Doughty...
Week 8: SRP / OCP SRP = Single Responsibility Principle Idea of splitting something down into their own single responsibilities Benefits of SRP: Reduction in complexity of the code Increase readability Better reusability and reduced errors Better testability Reduced Coupling OCP = Open / Closed principle Classes ( + other things) should be open for extension, but closed to modification New features should be implemented by writing new code, not by modifying existing code Benefits of OCP: Class becomes more robust Fewer bugs/errors can be introduced Better reusability Better testability SOLID S - SRP O - OCP L - Liskov Substitution Principle Methods that reference base classes must be able to use objects of derived classes without knowing it I - Interface Segregation Principle No class should be forced to depend on methods it doesn't use, ie. Implementing an interface and not using all the methods. D - Dependency Inversion Principle High-level classes should not depend on low-level classes. Both should depend on abstractions - ie. Interfaces....