Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
SOLID Principles
Presented by Mónica Rodrigues
January 24rd, 2017
Contents ➢ What is SOLID
➢ Single responsibility Principle
➢ Open/Closed Principle
➢ Liskov Substitution Principle
➢ Inter...
Who am I?
Mónica Rodrigues
Degree in Computer Science Engineer at ISEL
Software engineer since 2009
Keywords: Web Applicat...
What is SOLID?
S
SRP
Single
Responsibility
Principle
O
OCP
Open/Closed
Principle
L
LSP
Liskovs
Substitution
Principle
I
IS...
“A class should have one and
only one reason to change”
Single Responsibility Principle
Single Responsibility Principle
Business logic
Persistence
There are two
responsibilities
Single Responsibility Principle
How to solve this?
Single Responsibility Principle
Just create two different
classes
Open/Closed Principle
“Software entities should be
open for extension, but
closed for modification.”
Open/Closed Principle
Humm...and if I need to
add a new payment type?
You need to modificate
this class.
Open/Closed Principle
open for
extension
close for
modification
Liskov Substitution Principle
“Let q(x) be a property provable about
objects x of type T. Then q(y) should
be provable for...
Liskov Substitution Principle
“A subclass should behave in such a
way that it will not cause problems
when used instead of...
Liskov Substitution Principle
Liskov Substitution Principle
Much better
Interface Segregation Principle
“Clients should not be forced
to depend upon interfaces
that they don't use”
Interface Segregation Principle
Interface Segregation Principle
WHY?????
I don’t need you!!
Interface Segregation Principle
How to solve this?
Interface Segregation Principle
You need to create
two interfaces
Interface Segregation Principle
Dependency Inversion Principle
“High-level modules should not
depend on low-level modules. Both
should depend on abstracti...
Dependency Inversion Principle
And if I need to send a
notification by SMS?
You need to change this.
Dependency Inversion Principle
So, I create an
interface and now?
Dependency Inversion Principle
Dependency Inversion Principle
Constructor injection:
Dependency Inversion Principle
Property injection:
Dependency Inversion Principle
Method injection:
Keep in mind
DRY - Don’t repeat yourself
+
SLAP - Single layer abstraction principle
+
SOLID
BEST DEVELOPER
Enjoy code and
Keep it simple!
Thank you
Upcoming SlideShare
Loading in …5
×

Solid principles

1,115 views

Published on

SOLID principles

Published in: Engineering

Solid principles

  1. 1. SOLID Principles Presented by Mónica Rodrigues January 24rd, 2017
  2. 2. Contents ➢ What is SOLID ➢ Single responsibility Principle ➢ Open/Closed Principle ➢ Liskov Substitution Principle ➢ Interface Segregation Principle ➢ Dependency Inversion Principle
  3. 3. Who am I? Mónica Rodrigues Degree in Computer Science Engineer at ISEL Software engineer since 2009 Keywords: Web Applications, ASP.NET MVC, ASP.NET Web API, REST, Javascript, Angular, Best practices, Design patterns, SQL Server and much more..
  4. 4. What is SOLID? S SRP Single Responsibility Principle O OCP Open/Closed Principle L LSP Liskovs Substitution Principle I ISP Interface Segregation Principle D DIP Dependency Inversion Principle
  5. 5. “A class should have one and only one reason to change” Single Responsibility Principle
  6. 6. Single Responsibility Principle Business logic Persistence There are two responsibilities
  7. 7. Single Responsibility Principle How to solve this?
  8. 8. Single Responsibility Principle Just create two different classes
  9. 9. Open/Closed Principle “Software entities should be open for extension, but closed for modification.”
  10. 10. Open/Closed Principle Humm...and if I need to add a new payment type? You need to modificate this class.
  11. 11. Open/Closed Principle open for extension close for modification
  12. 12. Liskov Substitution Principle “Let q(x) be a property provable about objects x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T” What do you say?
  13. 13. Liskov Substitution Principle “A subclass should behave in such a way that it will not cause problems when used instead of the superclass.”
  14. 14. Liskov Substitution Principle
  15. 15. Liskov Substitution Principle Much better
  16. 16. Interface Segregation Principle “Clients should not be forced to depend upon interfaces that they don't use”
  17. 17. Interface Segregation Principle
  18. 18. Interface Segregation Principle WHY????? I don’t need you!!
  19. 19. Interface Segregation Principle How to solve this?
  20. 20. Interface Segregation Principle You need to create two interfaces
  21. 21. Interface Segregation Principle
  22. 22. Dependency Inversion Principle “High-level modules should not depend on low-level modules. Both should depend on abstractions.” “Abstractions should not depend upon details. Details should depend upon abstractions.”
  23. 23. Dependency Inversion Principle And if I need to send a notification by SMS? You need to change this.
  24. 24. Dependency Inversion Principle So, I create an interface and now?
  25. 25. Dependency Inversion Principle
  26. 26. Dependency Inversion Principle Constructor injection:
  27. 27. Dependency Inversion Principle Property injection:
  28. 28. Dependency Inversion Principle Method injection:
  29. 29. Keep in mind DRY - Don’t repeat yourself + SLAP - Single layer abstraction principle + SOLID BEST DEVELOPER
  30. 30. Enjoy code and Keep it simple!
  31. 31. Thank you

×