monica85rodrigues
18,223 views
31 slides
Jan 29, 2017
Slide 1 of 31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
About This Presentation
SOLID principles
Size: 2.08 MB
Language: en
Added: Jan 29, 2017
Slides: 31 pages
Slide Content
SOLID Principles Presented by Mónica Rodrigues January 24rd, 2017
Contents What is SOLID Single responsibility Principle Open/Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle
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..
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
“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 objects y of type S where S is a subtype of T ” What do you say?
Liskov Substitution Principle “A subclass should behave in such a way that it will not cause problems when used instead of the superclass.”
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 abstractions.” “Abstractions should not depend upon details. Details should depend upon abstractions.”
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?