clean code with solid principles

14
Clean code with SOLID principles SAHBI JABNOUNI

Upload: sahbi-jabnouni

Post on 13-Aug-2015

45 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Clean code with SOLID principles

Clean code with SOLID principles

SAHBI JABNOUNI

Page 2: Clean code with SOLID principles

Code smells

RIGIDITYFRAGILITYIMMOBILITYVISCOSITYDUPLICATION

Page 3: Clean code with SOLID principles

RIGIDITY:What The code is hard to change

Why Tight coupling

Result Not changing the code becomes a policy

Page 4: Clean code with SOLID principles

FRAGILITY:What The code breaks in many places every time

there is changes

Why Tight coupling

Result Long list of bugs

Page 5: Clean code with SOLID principles

IMMOBILTY:

What The code is hard to reuse

Why Tight coupling, many dependencies

Result Rewrite new code instead of reusing the existing one.

Page 6: Clean code with SOLID principles

VISCOSITY:

What Changes are easier by adding wrong things

Why Preserving the design is hard

Result Hacking code, code becomes bigger and more complicated

Page 7: Clean code with SOLID principles

DUPLICATION:

What Same code appears in many places.

Why Lack of abstraction.

Result Fixing same bug or adding same change in many places.

Page 8: Clean code with SOLID principles

SOLID Principals

SRP: Single Responsibility PrincipalOCP: Open/Close PrincipalLSP: Liscov Substitution PrincipleISP: Interface Segregation PrincipleDIP: Dependency Inversion Principle

Page 9: Clean code with SOLID principles

Single Responsibility Principle

Before using SRP After using SRP

• A class should have only one reason to change• Changes in requirement

Page 10: Clean code with SOLID principles

Open/Closed Principle

Before using OCP After using OCP

• Software entities should be open for extension, but closed for modification: BERTRAND MEYER.

Page 11: Clean code with SOLID principles

Liskov Substitution Principle

Before using LSP After using LSP

• Subtypes must be substitutable for their base type. BARBARA LISKOV

Page 12: Clean code with SOLID principles

Interface Segregation Principal

Before using ISP After using ISP

• Clients should not be forced to depend upon methods that they do not use.

Page 13: Clean code with SOLID principles

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

Page 14: Clean code with SOLID principles

THANK YOU