the solid principles Flashcards
why do we use the solid principles
they tell us how to arrange our functions and data structures into classes and how they should interact with eachother
source code dependency
high level units are dependant on what happens in the lower level units creating a hierarchy and making it harder to identify where a problem originated
what do we need in principles of good design
reduce coupling and increase cohesion
cohesion
each unit should be focused on one thing
what 3 things should we avoid in good design
rigid design
fragile design
immobile design
rigid design
every change may cause changes in other parts of the system
fragile design
the system breaks when a single change is made (due to high coupling)
immobile design
when code cant be reused
the design contains functionality that could be used in another system but the effect and risk of extracting it would be too big
srp
solid responsibility principle; a module should be responsible for only one actor
why is srp a problem (solid responsibility principle)
you may need to change the needs for one actor which would then change something for all other actors
what is the solution to solid responsibility principle
decouple; separate the code for different actors into separate code units
ocp
open-closed principle; classes should be open for extension but closed for modification
what is the benefit of open-closed principle
you reduce making errors when you have to make changes
what is the solution for open-closed principle
the class is changed to an interface and the old methods are turned into concrete classes
lsp
liskov substitution principle; the child class should inherit all features of the parent class