SlideShare a Scribd company logo
3
Most read
4
Most read
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 (20)

PPTX
S.O.L.I.D. Principles for Software Architects
Ricardo Wilkins
 
PPTX
SOLID principles
Jonathan Holloway
 
PDF
SOLID Design Principles applied in Java
Ionut Bilica
 
PPTX
Design principles - SOLID
Pranalee Rokde
 
PPTX
Reactjs
Neha Sharma
 
PPT
React js
Jai Santhosh
 
PPTX
Introduction to React JS
Arnold Asllani
 
PPTX
The Singleton Pattern Presentation
JAINIK PATEL
 
PPT
principles of object oriented class design
Neetu Mishra
 
PDF
Spring Boot
Jaydeep Kale
 
PDF
NextJS, A JavaScript Framework for building next generation SPA
Pramendra Gupta
 
KEY
SOLID Design Principles
Samuel Breed
 
PPTX
Solid design principles
Mahmoud Asadi
 
ODP
Geecon09: SOLID Design Principles
Bruno Bossola
 
PPT
TypeScript Presentation
Patrick John Pacaña
 
PPTX
React js
Oswald Campesato
 
PPTX
Refactoring Applications using SOLID Principles
Steven Smith
 
PPSX
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
PDF
React js
Rajesh Kolla
 
PDF
Clean architecture with asp.net core
Sam Nasr, MCSA, MVP
 
S.O.L.I.D. Principles for Software Architects
Ricardo Wilkins
 
SOLID principles
Jonathan Holloway
 
SOLID Design Principles applied in Java
Ionut Bilica
 
Design principles - SOLID
Pranalee Rokde
 
Reactjs
Neha Sharma
 
React js
Jai Santhosh
 
Introduction to React JS
Arnold Asllani
 
The Singleton Pattern Presentation
JAINIK PATEL
 
principles of object oriented class design
Neetu Mishra
 
Spring Boot
Jaydeep Kale
 
NextJS, A JavaScript Framework for building next generation SPA
Pramendra Gupta
 
SOLID Design Principles
Samuel Breed
 
Solid design principles
Mahmoud Asadi
 
Geecon09: SOLID Design Principles
Bruno Bossola
 
TypeScript Presentation
Patrick John Pacaña
 
Refactoring Applications using SOLID Principles
Steven Smith
 
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
React js
Rajesh Kolla
 
Clean architecture with asp.net core
Sam Nasr, MCSA, MVP
 

Similar to Learning solid principles using c# (20)

PPTX
OO Design Principles
Anju Kanjirathingal
 
PPTX
Object Oriented Design SOLID Principles
rainynovember12
 
PDF
Software design principles - jinal desai
jinaldesailive
 
PPTX
Design principle vs design patterns
Prabhakar Sharma
 
PPTX
Soild principles
Avidnyat Chiddarwar
 
PPTX
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
PPTX
CodeCamp Iasi 10 march 2012 - Scratching-SOLID
Codecamp Romania
 
PPTX
Solid
Romexsoft
 
PDF
Inversion of Control
Shuhab Tariq
 
PPTX
An ultimate guide to SOLID Principles, developers must know.
ONE BCG
 
PPTX
SOLID Software Principles with C#
Ken Burkhardt
 
PPTX
Solid
Hadi Ehterami
 
PPTX
Concepts of oops
Sourabrata Mukherjee
 
PDF
Solid principles
Nhan Nguyen
 
PPTX
Solid Principles
Gaurav Mishra
 
PDF
4K Video Downloader Crack 4.28.0.5600 + License Key [2025]
hyderik195
 
PDF
Wondershare Filmora Crack 14.3.2 + Key Full Download
hyderik195
 
PDF
Adobe Photoshop 2025 Free crack Download
juttjolie9
 
PDF
Adobe Photoshop Lightroom Classic Crack Free Download
adnan01kp
 
PDF
Adobe Photoshop 2025 Free crack Download
adnan01kp
 
OO Design Principles
Anju Kanjirathingal
 
Object Oriented Design SOLID Principles
rainynovember12
 
Software design principles - jinal desai
jinaldesailive
 
Design principle vs design patterns
Prabhakar Sharma
 
Soild principles
Avidnyat Chiddarwar
 
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
CodeCamp Iasi 10 march 2012 - Scratching-SOLID
Codecamp Romania
 
Solid
Romexsoft
 
Inversion of Control
Shuhab Tariq
 
An ultimate guide to SOLID Principles, developers must know.
ONE BCG
 
SOLID Software Principles with C#
Ken Burkhardt
 
Concepts of oops
Sourabrata Mukherjee
 
Solid principles
Nhan Nguyen
 
Solid Principles
Gaurav Mishra
 
4K Video Downloader Crack 4.28.0.5600 + License Key [2025]
hyderik195
 
Wondershare Filmora Crack 14.3.2 + Key Full Download
hyderik195
 
Adobe Photoshop 2025 Free crack Download
juttjolie9
 
Adobe Photoshop Lightroom Classic Crack Free Download
adnan01kp
 
Adobe Photoshop 2025 Free crack Download
adnan01kp
 
Ad

Recently uploaded (20)

PDF
July Patch Tuesday
Ivanti
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
July Patch Tuesday
Ivanti
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Python basic programing language for automation
DanialHabibi2
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Ad

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)