SlideShare a Scribd company logo
S.O.L.I.D Principles
using C#
And the principles are…
 S Single Responsibility Principle
 O Open Closed Principle
 L Liskovs Substitution Principle
 I Interface Segregation Principle
 D Dependency Inversion principle
Single Responsibility Principle
“A class should have one reason to change”
Meaning
There can be only one requirement that when changed, will cause a
class to change.
How to do this ?
breaking your story/requirement/code to smaller chunks/class in
such a way that all common behavior is being grouped together
under one component.
Single Responsibility means your class to be very focused
Outcome
You will end up having multiple classes, precise about one specific
behavior. Each of this class can now be used as a component.
Open Closed Principles
“Your class/module/contracts should be open for extension
and closed for modification”
Meaning
You should be able to extend the behavior of a class
without changing it.
Once a class is done, it should not be modified.
How to do this ?
Creating new class by using inheritance
or
abstraction
Open Closed Principle
To implement OCP, we should be SRP,
so that we can identify and separate behavior that
change into multiple classes, such that
things that change frequently depends on things that
don’t.
Output
Lots of components(class) for same behavior but
different implementation
Liskovs Substitution Principle
“If for each object o1 of type S there is an object o2 of
type T such that for all programs P defined in terms
of T, the behavior of P is unchanged when o1 is
substituted for o2, then S is a subtype of T.”
Meaning
We should be able to substitute every derived class for
there parent class. A subclass (outcome of OCP)
should behave in such a way that it will not cause
problem when used instead of its super
class(outcome of SRP)
Liskovs Substitution Principle
How to do this ?
Pre conditions cannot be strengthened in a subtype
&
Post conditions can not be weakened in a subtype.
No new exceptions types are allowed to be thrown unless
they are subclasses of previously used one.
You can not make mutable to immutable vice versa.
Output
Plug and play components.
Interface Segregation Principle
“Clients should not be forced to depend upon
interfaces that they don’t use.”
How to do this?
Breaking down interfaces in smaller pieces and
combining interfaces to generate a super interfaces.
Output
Smaller Interfaces with specific responsibility.
Dependency Inversion Principle
“High level module should not depend on low level
module. Both should depend on abstraction.
Abstraction should not depend upon details. Details
should depend upon abstraction.”
Meaning
Your classes should not depend on specific
implementation, avoid instantiation of a class X
inside another Y, as this makes your class Y directly
dependent on X and any change in X might break Y.
Dependency Inversion Principle
Example:
If business decides to change Business Logic or database, this model does for a complete change, because business login is
directly instantiating repository layer and same for UI. UI is calling business logic layer by directly creating an object of
it.
We should not use NEW keyword inside a class as this creates a dependency.
How to do this?
By using Interfaces or Abstract classes to create generic types or holder to hold any class implementing that interface or
abstract class.
By not using NEW keyword to instantiate an object and instead inject the dependencies using constructor or property.
If NEW is not to be used, then who will create required object?
We achieve this by using Dependency Injection tools like Unity, Structure Map.
By having a Abstract Factory Method responsible for create of new object.
UI
Layer
Reposi
tory
Layer
Busine
ss
Logic
DB
Done !!!
Few Points to consider…
 Try avoiding over engineering and keep the solution
simple and readable.
 Decide how far you want to go with SOLID, as
splitting requirement to SOLID principles is
debatable.
 Project size (LOC)

More Related Content

What's hot

Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
Aman Jain
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
Marco Mangia Musardo
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
akbarashaikh
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
NexThoughts Technologies
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
Shahriar Hyder
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
Indeema Software Inc.
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
Thiago Dos Santos Hora
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
Ionut Bilica
 
Solid Principle
Solid PrincipleSolid Principle
Solid Principle
Murali Pachiyappan
 
Clean architecture
Clean architectureClean architecture
Clean architecture
Travis Frisinger
 
Clean architecture
Clean architectureClean architecture
Clean architecture
Lieven Doclo
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
Shakil Ahmed
 
Abstract class
Abstract classAbstract class
Abstract class
Tony Nguyen
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
Sergey Karpushin
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsS.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software Architects
Ricardo Wilkins
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
Jm Ramos
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
Jamie (Taka) Wang
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
Asma CHERIF
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
Pablo Villar
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
Mahmoud Asadi
 

What's hot (20)

Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Dependency Inversion Principle
Dependency Inversion PrincipleDependency Inversion Principle
Dependency Inversion Principle
 
Clean code: SOLID
Clean code: SOLIDClean code: SOLID
Clean code: SOLID
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Solid Principle
Solid PrincipleSolid Principle
Solid Principle
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Abstract class
Abstract classAbstract class
Abstract class
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
S.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software ArchitectsS.O.L.I.D. Principles for Software Architects
S.O.L.I.D. Principles for Software Architects
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
 

Similar to Learning solid principles using c#

OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
Anju Kanjirathingal
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
jinaldesailive
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patterns
Prabhakar Sharma
 
Soild principles
Soild principlesSoild principles
Soild principles
Avidnyat Chiddarwar
 
Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
CodeCamp Iasi 10 march 2012 - Scratching-SOLID
CodeCamp Iasi 10 march 2012 - Scratching-SOLIDCodeCamp Iasi 10 march 2012 - Scratching-SOLID
CodeCamp Iasi 10 march 2012 - Scratching-SOLID
Codecamp Romania
 
Solid
SolidSolid
Solid
Romexsoft
 
Inversion of Control
Inversion of ControlInversion of Control
Inversion of Control
Shuhab Tariq
 
An ultimate guide to SOLID Principles, developers must know.
An ultimate guide to SOLID Principles, developers must know.An ultimate guide to SOLID Principles, developers must know.
An ultimate guide to SOLID Principles, developers must know.
ONE BCG
 
SOLID Software Principles with C#
SOLID Software Principles with C#SOLID Software Principles with C#
SOLID Software Principles with C#
Ken Burkhardt
 
Solid
SolidSolid
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
Sourabrata Mukherjee
 
Solid principles
Solid principlesSolid principles
Solid principles
Nhan Nguyen
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
Gaurav Mishra
 
SOLID
SOLIDSOLID
SOLID principles-Present
SOLID principles-PresentSOLID principles-Present
SOLID principles-Present
Quang Nguyen
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
Basavaraj Patil
 
Solid principles
Solid principlesSolid principles
Solid principles
Kumaresh Chandra Baruri
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
Faizan Haider
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
Irwansyah Irwansyah
 

Similar to Learning solid principles using c# (20)

OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patterns
 
Soild principles
Soild principlesSoild principles
Soild principles
 
Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
 
CodeCamp Iasi 10 march 2012 - Scratching-SOLID
CodeCamp Iasi 10 march 2012 - Scratching-SOLIDCodeCamp Iasi 10 march 2012 - Scratching-SOLID
CodeCamp Iasi 10 march 2012 - Scratching-SOLID
 
Solid
SolidSolid
Solid
 
Inversion of Control
Inversion of ControlInversion of Control
Inversion of Control
 
An ultimate guide to SOLID Principles, developers must know.
An ultimate guide to SOLID Principles, developers must know.An ultimate guide to SOLID Principles, developers must know.
An ultimate guide to SOLID Principles, developers must know.
 
SOLID Software Principles with C#
SOLID Software Principles with C#SOLID Software Principles with C#
SOLID Software Principles with C#
 
Solid
SolidSolid
Solid
 
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
SOLID
SOLIDSOLID
SOLID
 
SOLID principles-Present
SOLID principles-PresentSOLID principles-Present
SOLID principles-Present
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Design Principles to design Patterns
Design Principles to design PatternsDesign Principles to design Patterns
Design Principles to design Patterns
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 

Recently uploaded

Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 

Recently uploaded (20)

Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 

Learning solid principles using c#

  • 2. And the principles are…  S Single Responsibility Principle  O Open Closed Principle  L Liskovs Substitution Principle  I Interface Segregation Principle  D Dependency Inversion principle
  • 3. Single Responsibility Principle “A class should have one reason to change” Meaning There can be only one requirement that when changed, will cause a class to change. How to do this ? breaking your story/requirement/code to smaller chunks/class in such a way that all common behavior is being grouped together under one component. Single Responsibility means your class to be very focused Outcome You will end up having multiple classes, precise about one specific behavior. Each of this class can now be used as a component.
  • 4. Open Closed Principles “Your class/module/contracts should be open for extension and closed for modification” Meaning You should be able to extend the behavior of a class without changing it. Once a class is done, it should not be modified. How to do this ? Creating new class by using inheritance or abstraction
  • 5. Open Closed Principle To implement OCP, we should be SRP, so that we can identify and separate behavior that change into multiple classes, such that things that change frequently depends on things that don’t. Output Lots of components(class) for same behavior but different implementation
  • 6. Liskovs Substitution Principle “If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T.” Meaning We should be able to substitute every derived class for there parent class. A subclass (outcome of OCP) should behave in such a way that it will not cause problem when used instead of its super class(outcome of SRP)
  • 7. Liskovs Substitution Principle How to do this ? Pre conditions cannot be strengthened in a subtype & Post conditions can not be weakened in a subtype. No new exceptions types are allowed to be thrown unless they are subclasses of previously used one. You can not make mutable to immutable vice versa. Output Plug and play components.
  • 8. Interface Segregation Principle “Clients should not be forced to depend upon interfaces that they don’t use.” How to do this? Breaking down interfaces in smaller pieces and combining interfaces to generate a super interfaces. Output Smaller Interfaces with specific responsibility.
  • 9. Dependency Inversion Principle “High level module should not depend on low level module. Both should depend on abstraction. Abstraction should not depend upon details. Details should depend upon abstraction.” Meaning Your classes should not depend on specific implementation, avoid instantiation of a class X inside another Y, as this makes your class Y directly dependent on X and any change in X might break Y.
  • 10. Dependency Inversion Principle Example: If business decides to change Business Logic or database, this model does for a complete change, because business login is directly instantiating repository layer and same for UI. UI is calling business logic layer by directly creating an object of it. We should not use NEW keyword inside a class as this creates a dependency. How to do this? By using Interfaces or Abstract classes to create generic types or holder to hold any class implementing that interface or abstract class. By not using NEW keyword to instantiate an object and instead inject the dependencies using constructor or property. If NEW is not to be used, then who will create required object? We achieve this by using Dependency Injection tools like Unity, Structure Map. By having a Abstract Factory Method responsible for create of new object. UI Layer Reposi tory Layer Busine ss Logic DB
  • 11. Done !!! Few Points to consider…  Try avoiding over engineering and keep the solution simple and readable.  Decide how far you want to go with SOLID, as splitting requirement to SOLID principles is debatable.  Project size (LOC)