solid Flashcards
[S]ingle Responsibility Principle| SRP
A class should have one, and only one, reason to change.Cohesion is defined as the functional affinity of a Module’s element.
[O]pen/Closed Principle| OCP
You should be able to extend a classes behavior, without modifying it.Note: Type classes were introduced first in Haskell as a new approach to ad-hoc polymorphism.
[L]iskov Substitution Principle| LSP
Derived classes must be replaceable for their base classes.LSP is the enabling principle of the Open/Closed PrincipleDespite Inheritance is a powerful mechanism, it must be used contextualized and moderating, avoiding cases of classes being extended only by having something in common.Composition is easier to test , to maintain and less prone to errorsTraits concernsTraits to model behaviors
[I]nterface Segregation Principle| ISP
it’s better to have very specific interfaces than a general interfaceInterfaces that have many Behaviors are difficult to maintain and evolve.Make fine grained interfaces that are client specificCohesion in InterfacesInterfaces = Behaviors“fat” classes, can cause bizarre and damaging couplings to business rules.
[D]ependency Inversion Principle| DIP
Depend on abstractions, not on concretions.“High-level modules should not depend on low-level modules. Both should depend on abstractions.”“Abstractions should not depend on details. Details should depend on abstractions.”Abstractions change less and make it easier to change behaviors and future code evolutions.
S.O.L.I.D
is an acronym that represents five principles of object-oriented programming and code design theorized by our beloved Uncle Bob
Cohesion
Cohesion is defined as the functional affinity of a Module’s element.It refers to the Relationship that the Members of this Module have if they have a more Direct and Important Relationship.