Solid principles
-
Upload
monica-rodrigues -
Category
Engineering
-
view
243 -
download
1
Transcript of Solid principles
![Page 1: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/1.jpg)
SOLID PrinciplesPresented by Mónica Rodrigues
January 24rd, 2017
![Page 2: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/2.jpg)
Contents
➢ What is SOLID➢ Single responsibility Principle➢ Open/Closed Principle➢ Liskov Substitution Principle➢ Interface Segregation
Principle
➢ Dependency Inversion Principle
![Page 3: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/3.jpg)
Who am I?Mónica RodriguesDegree 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..
![Page 4: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/4.jpg)
What is SOLID?
SSRPSingleResponsibilityPrinciple
OOCPOpen/ClosedPrinciple
LLSPLiskovsSubstitutionPrinciple
IISPInterfaceSegregationPrinciple
DDIPDependencyInversionPrinciple
![Page 5: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/5.jpg)
“A class should have one and
only one reason to change”
Single Responsibility Principle
![Page 6: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/6.jpg)
Single Responsibility Principle
Business logic
Persistence
There are two responsibilities
![Page 7: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/7.jpg)
Single Responsibility Principle
How to solve this?
![Page 8: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/8.jpg)
Single Responsibility Principle
Just create two different classes
![Page 9: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/9.jpg)
Open/Closed Principle
“Software entities should be open for extension, but closed for modification.”
![Page 10: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/10.jpg)
Open/Closed Principle
Humm...and if I need to add a new payment type?
You need to modificate this class.
![Page 11: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/11.jpg)
Open/Closed Principleopen for extension
close for modification
![Page 12: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/12.jpg)
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?
![Page 13: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/13.jpg)
Liskov Substitution Principle
“A subclass should behave in such a way that it will not
cause problems when used instead of the superclass.”
![Page 14: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/14.jpg)
Liskov Substitution Principle
![Page 15: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/15.jpg)
Liskov Substitution Principle
Much better
![Page 16: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/16.jpg)
Interface Segregation Principle
“Clients should not be forced to depend upon
interfaces that they don't use”
![Page 17: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/17.jpg)
Interface Segregation Principle
![Page 18: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/18.jpg)
Interface Segregation Principle
WHY?????I don’t need you!!
![Page 19: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/19.jpg)
Interface Segregation Principle
How to solve this?
![Page 20: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/20.jpg)
Interface Segregation Principle
You need to create two interfaces
![Page 21: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/21.jpg)
Interface Segregation Principle
![Page 22: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/22.jpg)
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.”
![Page 23: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/23.jpg)
Dependency Inversion Principle
And if I need to send a notification by SMS?You need to change this.
![Page 24: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/24.jpg)
Dependency Inversion PrincipleSo, I create an interface and now?
![Page 25: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/25.jpg)
Dependency Inversion Principle
![Page 26: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/26.jpg)
Dependency Inversion PrincipleConstructor injection:
![Page 27: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/27.jpg)
Dependency Inversion PrincipleProperty injection:
![Page 28: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/28.jpg)
Dependency Inversion PrincipleMethod injection:
![Page 29: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/29.jpg)
Keep in mindDRY - Don’t repeat yourself+ SLAP - Single layer abstraction principle + SOLID BEST
DEVELOPER
![Page 30: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/30.jpg)
Enjoy code and Keep it simple!
![Page 31: Solid principles](https://reader036.fdocuments.in/reader036/viewer/2022062522/58a7c84d1a28ab6b5a8b5c9d/html5/thumbnails/31.jpg)
Thank you