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 O L I D
SRP OCP LSP ISP DIP
Single Liskovs Interface Dependency
Open/Closed
Responsibility Substitution Segregation Inversion
Principle
Principle Principle Principle Principle
Single Responsibility Principle
“A class should have one and
only one reason to change”
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 - Don’t repeat yourself
+
SLAP - Single layer abstraction principle
+
SOLID
BEST DEVELOPER
Enjoy code and
Keep it simple!
Thank you