You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use SOLID principles to address design deficiencies
Some problems without SOLID
Mixed responsibility
Missing responsibility
Limited reuse potential
Not substitutable
S.O.L.I.D - Order doesn't matter
Interface segregation
Helps design good classes
Helps write unit test cases
Asks you to create a different interface for different responsibilities, in other words, don't group unrelated behavior in one interface, You break ISP if You have already an interface with many responsibilities, and the implementor doesn't need all this stuff.
Liskov substitution - how subclasses extend superclasses
This principle asks you to make sure that all child classes have the same behavior as the parent class. Object of superclass S can be replaced with objects of any subclass of S.
Helps design good polymorphism
Ex: Square-Rectangle Problem
Open/closed - tuning the design
Open to extension means adding subclasses a needed
Closed to modification avoids "tweaking" the code to handle new situations
Allow its behavior to be extended without modifying its source code. Factory → we need to update the objects list only, method names are the same.
Dependency inversion - based on packaging the code. Decrease the dependency on another concrete class.
A direct dependency on a concrete class needs to be "inverted"
Depend on abstraction classes
Avoid concrete class name dependencies
Single responsibility - summary of other 4 principles
One responsibility per class.
"A class should have one reason to change"
Note!! "Single" at what level of abstraction? How are the responsibilities counter?
Other OO Principle
Don't repeat yourself (DRY)
General responsibility assignment software principles (GRASP)