Solid principles

monica85rodrigues 18,223 views 31 slides Jan 29, 2017
Slide 1
Slide 1 of 31
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31

About This Presentation

SOLID principles


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?

Dependency Inversion Principle

Dependency Inversion Principle Constructor injection:

Dependency Inversion Principle Property injection:

Dependency Inversion Principle Method injection:

Keep in mind DRY - D on’t r epeat y ourself + SLAP - S ingle l ayer a bstraction p rinciple + SOLID BEST DEVELOPER

Enjoy code and Keep it simple!

Thank you