clean code with solid principles
TRANSCRIPT
Clean code with SOLID principles
SAHBI JABNOUNI
Code smells
RIGIDITYFRAGILITYIMMOBILITYVISCOSITYDUPLICATION
RIGIDITY:What The code is hard to change
Why Tight coupling
Result Not changing the code becomes a policy
FRAGILITY:What The code breaks in many places every time
there is changes
Why Tight coupling
Result Long list of bugs
IMMOBILTY:
What The code is hard to reuse
Why Tight coupling, many dependencies
Result Rewrite new code instead of reusing the existing one.
VISCOSITY:
What Changes are easier by adding wrong things
Why Preserving the design is hard
Result Hacking code, code becomes bigger and more complicated
DUPLICATION:
What Same code appears in many places.
Why Lack of abstraction.
Result Fixing same bug or adding same change in many places.
SOLID Principals
SRP: Single Responsibility PrincipalOCP: Open/Close PrincipalLSP: Liscov Substitution PrincipleISP: Interface Segregation PrincipleDIP: Dependency Inversion Principle
Single Responsibility Principle
Before using SRP After using SRP
• A class should have only one reason to change• Changes in requirement
Open/Closed Principle
Before using OCP After using OCP
• Software entities should be open for extension, but closed for modification: BERTRAND MEYER.
Liskov Substitution Principle
Before using LSP After using LSP
• Subtypes must be substitutable for their base type. BARBARA LISKOV
Interface Segregation Principal
Before using ISP After using ISP
• Clients should not be forced to depend upon methods that they do not use.
Dependency Inversion Principal
Before using DIP After using DIP
• High-Level modules should not depend on Low-Level modules. Both should depend on ABTRACTIONS : ROBERT MARTIN
THANK YOU