SlideShare a Scribd company logo
1 of 28
eleks.comeleks.com
SOLID AND IOC PRINCIPLES
The first five principles of OOP design… And the
additional one
Mykhailo Romaniuk
Single Responsibility Principle
SRP
A class should have only one reason to change
Robert C. Martin
SRP
States that every module or class should have
responsibility over a single part of the
functionality provided by the software, and that
responsibility should be entirely encapsulated
by the class
Open/Closed Principle
OCP
Objects or entities should be open for
extension, but closed for modification
Bertrand Meyer
OCP
States that software entities (classes, modules,
functions, etc.) should be open for extension,
but closed for modification, that is, such an
entity can allow its behavior to be extended
without modifying its source code
Liskov Substitution Principle
Can a toy-dog woof without batteries?
LSP
Let f(x) be a property of objects X of type T.
Then f(y) should be true for objects Y of type S
where S is a subtype of T
Barbara Liskov
LSP
States that if S is a subtype of T, then objects of
type T may be replaced with objects of type S
without altering any of the desirable properties
of that program (correctness, task performed)
Interface Segregation Principle
ISP
Many client-specific interfaces are better than
one general-purpose interface
Robert C. Martin
ISP
States that no client should be forced to depend
on methods it does not use. Thus having
multiple grained interfaces is better that one.
Dependency Inversion Principle
DIP
One should depend upon abstractions, not on
concretions
Robert C. Martin
DIP
A. High-level modules should not depend on
low-level modules. Both should depend on
abstractions.
B. Abstractions should not depend on details.
Details should depend on abstractions.
Inversion of Control Principle
What Is IoC?
In software engineering, IoC describes a design in which
custom-written portions of a computer program receive the
flow of control from a generic, reusable library.
Wikipedia
“How To IoC”?
• Events
• Delegates
• Dependency
Injection
Dependency Injection
Dependency injection means giving an object
it’s instance variables. Really. That's it.
James Shore
What Should I Use For DI?
Windsor
Injection Types
• Constructor
Injection
• Using Property
• Thru Initialization
Method
Software Testability
If your code isn't testable, then you have a
design problem
Common Sense
What Makes Your Software Testable?
• SRP. Since type is doing only one job, you can
clearly understand what should be tested.
• LSP. Since types used can be replaced with
subtypes, mocks and stubs can be used instead
of real types.
• ISP. Since there are more granular client-specific
interfaces, you know exactly what to mock.
Let’s Review Some Concepts
• Reusable. Higher-level
components can be reused if
lower-lever components change
with time to meet the
requirements.
• Extensible. Software is easily
extended with new components
and features because design is
based on abstractions.
• Replaceable. Lower-level
components can be replaced to
meet new requirements without
modifying existing code.
• Loosely Coupled. Allows
components to perform on their
own with as little knowledge as
possible about other
components.
• Cohesive. Build you software
easily with different components
as building blocks.
• Testable. It is easy to understand
what and how to test in each
component because components
are loosely-coupled.
Thanks! Any Questions?
What can you read at home?
• Wikipedia about SOLID
https://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29
• Nice article about SOLID with examples
https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
• Dive deeper into SOLID
http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
• SOLID explanation with examples:
http://www.codemag.com/article/1001061
• Simple explanation of DI for beginners
http://www.jamesshore.com/Blog/Dependency-Injection-Demystified.html
• IoC and DI
http://martinfowler.com/articles/injection.html
eleks.com
Inspired by Technology.
Driven by Value.

More Related Content

What's hot

What's hot (10)

Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)Introduction to Aspect Oriented Programming (DDD South West 4.0)
Introduction to Aspect Oriented Programming (DDD South West 4.0)
 
Embodiment of a neural simulation
Embodiment of a neural simulationEmbodiment of a neural simulation
Embodiment of a neural simulation
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
A DSL for Your API
A DSL for Your APIA DSL for Your API
A DSL for Your API
 
What's Missing in Language Workbenches
What's Missing in Language WorkbenchesWhat's Missing in Language Workbenches
What's Missing in Language Workbenches
 
Introduction To Aspect Oriented Programming
Introduction To Aspect Oriented ProgrammingIntroduction To Aspect Oriented Programming
Introduction To Aspect Oriented Programming
 
Aspect Oriented Programing - Introduction
Aspect Oriented Programing - IntroductionAspect Oriented Programing - Introduction
Aspect Oriented Programing - Introduction
 
Solid
SolidSolid
Solid
 
Train track assembly
Train track assemblyTrain track assembly
Train track assembly
 

Viewers also liked (20)

Unit1 summary
Unit1 summaryUnit1 summary
Unit1 summary
 
SQL Grouping, Joins
SQL Grouping, JoinsSQL Grouping, Joins
SQL Grouping, Joins
 
SDLC. PM Role
SDLC. PM RoleSDLC. PM Role
SDLC. PM Role
 
Improving rpc bkp
Improving rpc bkpImproving rpc bkp
Improving rpc bkp
 
Version control
Version controlVersion control
Version control
 
tsql
tsqltsql
tsql
 
Windows service
Windows serviceWindows service
Windows service
 
Frontend basics
Frontend basicsFrontend basics
Frontend basics
 
DAL
DALDAL
DAL
 
Advanced styles
Advanced stylesAdvanced styles
Advanced styles
 
If unit2 summary
If unit2 summaryIf unit2 summary
If unit2 summary
 
SQL: Indexes, Select operator
SQL: Indexes, Select operatorSQL: Indexes, Select operator
SQL: Indexes, Select operator
 
#4 code quality
#4 code quality#4 code quality
#4 code quality
 
Rpc
RpcRpc
Rpc
 
Code Practices
Code PracticesCode Practices
Code Practices
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Sql 04n edited
Sql 04n editedSql 04n edited
Sql 04n edited
 
Advanced c sharp part 3
Advanced c sharp part 3Advanced c sharp part 3
Advanced c sharp part 3
 
Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patterns
 
SDLC. QA Role
SDLC. QA RoleSDLC. QA Role
SDLC. QA Role
 

Similar to Solid and ioc principles

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
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 

Similar to Solid and ioc principles (20)

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
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
How To Write a Testable Code
How To Write a Testable CodeHow To Write a Testable Code
How To Write a Testable Code
 
Spring fundamentals
Spring fundamentalsSpring fundamentals
Spring fundamentals
 
OOP Java
OOP JavaOOP Java
OOP Java
 
Design for testability as a way to good coding (SOLID and IoC)
Design for testability as a way to good coding (SOLID and IoC)Design for testability as a way to good coding (SOLID and IoC)
Design for testability as a way to good coding (SOLID and IoC)
 
OO Design Principles
OO Design PrinciplesOO Design Principles
OO Design Principles
 
N-tier and oop - moving across technologies
N-tier and oop - moving across technologiesN-tier and oop - moving across technologies
N-tier and oop - moving across technologies
 
Solid principes
Solid principesSolid principes
Solid principes
 
Why functional programming in C# & F#
Why functional programming in C# & F#Why functional programming in C# & F#
Why functional programming in C# & F#
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
1 intro
1 intro1 intro
1 intro
 
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC TeamAOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
AOP-IOC made by Vi Quoc Hanh and Vu Cong Thanh in SC Team
 
Xcore meets IncQuery: How the New Generation of DSLs are Made
Xcore meets IncQuery: How the New Generation of DSLs are MadeXcore meets IncQuery: How the New Generation of DSLs are Made
Xcore meets IncQuery: How the New Generation of DSLs are Made
 
Geecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesGeecon09: SOLID Design Principles
Geecon09: SOLID Design Principles
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
 
Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Solid principle
Solid principleSolid principle
Solid principle
 
The software design principles
The software design principlesThe software design principles
The software design principles
 

More from eleksdev (16)

Lecture android best practices
Lecture   android best practicesLecture   android best practices
Lecture android best practices
 
Communication in android
Communication in androidCommunication in android
Communication in android
 
Hello android world
Hello android worldHello android world
Hello android world
 
Angular. presentation
Angular. presentationAngular. presentation
Angular. presentation
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors API
 
Lecture java basics
Lecture   java basicsLecture   java basics
Lecture java basics
 
Css animation, html5 api
Css animation, html5 apiCss animation, html5 api
Css animation, html5 api
 
G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2
 
G rpc lection1
G rpc lection1G rpc lection1
G rpc lection1
 
Aspnet core
Aspnet coreAspnet core
Aspnet core
 
Web service lecture
Web service lectureWeb service lecture
Web service lecture
 
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
 
SDLC. UX Role
SDLC. UX RoleSDLC. UX Role
SDLC. UX Role
 
SDLC. BA Role
SDLC. BA RoleSDLC. BA Role
SDLC. BA Role
 
NoSQL basics
NoSQL basicsNoSQL basics
NoSQL basics
 
sql introduction
sql introductionsql introduction
sql introduction
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Solid and ioc principles

  • 1. eleks.comeleks.com SOLID AND IOC PRINCIPLES The first five principles of OOP design… And the additional one Mykhailo Romaniuk
  • 3. SRP A class should have only one reason to change Robert C. Martin
  • 4. SRP States that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class
  • 6. OCP Objects or entities should be open for extension, but closed for modification Bertrand Meyer
  • 7. OCP States that software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification, that is, such an entity can allow its behavior to be extended without modifying its source code
  • 8. Liskov Substitution Principle Can a toy-dog woof without batteries?
  • 9. LSP Let f(x) be a property of objects X of type T. Then f(y) should be true for objects Y of type S where S is a subtype of T Barbara Liskov
  • 10. LSP States that if S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of that program (correctness, task performed)
  • 12. ISP Many client-specific interfaces are better than one general-purpose interface Robert C. Martin
  • 13. ISP States that no client should be forced to depend on methods it does not use. Thus having multiple grained interfaces is better that one.
  • 15. DIP One should depend upon abstractions, not on concretions Robert C. Martin
  • 16. DIP A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend on details. Details should depend on abstractions.
  • 17. Inversion of Control Principle
  • 18. What Is IoC? In software engineering, IoC describes a design in which custom-written portions of a computer program receive the flow of control from a generic, reusable library. Wikipedia
  • 19. “How To IoC”? • Events • Delegates • Dependency Injection
  • 20. Dependency Injection Dependency injection means giving an object it’s instance variables. Really. That's it. James Shore
  • 21. What Should I Use For DI? Windsor
  • 22. Injection Types • Constructor Injection • Using Property • Thru Initialization Method
  • 23. Software Testability If your code isn't testable, then you have a design problem Common Sense
  • 24. What Makes Your Software Testable? • SRP. Since type is doing only one job, you can clearly understand what should be tested. • LSP. Since types used can be replaced with subtypes, mocks and stubs can be used instead of real types. • ISP. Since there are more granular client-specific interfaces, you know exactly what to mock.
  • 25. Let’s Review Some Concepts • Reusable. Higher-level components can be reused if lower-lever components change with time to meet the requirements. • Extensible. Software is easily extended with new components and features because design is based on abstractions. • Replaceable. Lower-level components can be replaced to meet new requirements without modifying existing code. • Loosely Coupled. Allows components to perform on their own with as little knowledge as possible about other components. • Cohesive. Build you software easily with different components as building blocks. • Testable. It is easy to understand what and how to test in each component because components are loosely-coupled.
  • 27. What can you read at home? • Wikipedia about SOLID https://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29 • Nice article about SOLID with examples https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design • Dive deeper into SOLID http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod • SOLID explanation with examples: http://www.codemag.com/article/1001061 • Simple explanation of DI for beginners http://www.jamesshore.com/Blog/Dependency-Injection-Demystified.html • IoC and DI http://martinfowler.com/articles/injection.html