Successfully reported this slideshow.

Solid principles



Loading in …3
1 of 31
1 of 31

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

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