SOLID principles
I’m reviewing the SOLID principles of OOP and I read this article and made a few notes on it. These aren’t meant to make sense to anyone except me.
S is for SOLID
Single reponsbility principle - means a class or a method should do one thing a method that swuares a number and prints its result “A class should have one and only one reason to change” it’s to avoid unnecessary coupling between classes and lower the complexity of changes
Open / Closed
Interfaces are closed for modification but they can be augmented in their implementations. “It promotes the use of interfaces to enable you to adapt the functionality of your application without changing the existing code.”
Liskov Substitution
Objects of a superclass can be replaced by members of their subclass and the app’s behaviour will not change Overridden methods of a subclass should have the same signature as methods of the superclass. Methods in a subclass can’t use stricter validation rules. A compiler can’t enforce this so it has to happen via tests.
“Don’t implement any stricter validation rules on input parameters than implemented by the parent class. Apply at the least the same rules to all output parameters as applied by the parent class.”
Interface Segregation
Aims to reduce complexity and side effects of code changes An interface should relate to all classes that implement it and no class should interface methods it does not use just so it compiles. Conversely an interface shouldn’t have to contain methods for all its different children.
Dependency Inversion
“High-level modules should not depend on low-level modules. Both should depend on abstractions.” Allow for composition of abstractions This principle allows changing higher and lower level classes without affecting other classes