SlideShare a Scribd company logo
1 of 10
SOLID
Design Principles
By Divanshu Nandwani
Agenda
History Definition
Examples Q&A
History
● 80% of software projects fails
● The theory of SOLID principles was
introduced by Robert C. Martin in his 2000
paper “Design Principles and Design
Patterns”
● The SOLID acronym itself was introduced
later by Michael Feathers
Definition
● Single responsibility principle
A class should have only a single responsibility (i.e. changes to only one part of the software's
specification should be able to affect the specification of the class).
● Open/closed principle
"software entities … should be open for extension, but closed for modification."
● Liskov substitution principle
"objects in a program should be replaceable with instances of their subtypes without altering the
correctness of that program."
● Interface segregation principle
"many client-specific interfaces are better than one general-purpose interface.”
● Dependency inversion principle
one should "depend upon abstractions, [not] concretions."
Example of Single responsibility principle
Without “S”
class UserService {
void changePassword(User user) {
if(checkAccess(user)) {
//Grant option to change
}
}
boolean checkAccess(User user) {
//Verify if the user is valid.
}
}
With “S”
class UserService {
void changePassword(User user) {
if(SecurityService.checkAccess(user)) {
//Grant option to change
}
}
}
class SecurityService {
static boolean checkAccess(User user) {
//check the access.
}
}
Example of Open/closed principle
Without “O”
class LoanApprovalHandler {
void approve(PersonalLoanValidator
validator) {
if ( validator.isValid()) {
//Process the loan.
}
}
}
class PersonalLoanValidator {
boolean isValid() {
//Validation logic
}
}
With “O”
interface Validator {boolean isValid();}
class PersonalLoanValidator implements
Validator {
boolean isValid() {}
}
class HomeLoanValidator implements Validator {
boolean isValid() {}
}
class LoanApprovalHandler {
void approve(Validator validator) {
if ( validator.isValid()) {
//Process the loan.
}
}
}
Example of Liskov substitution principle
Without “L”
class Bird {
public void fly(){}
public void eat(){}
}
class Sparrow extends Bird {}
class Ostrich extends Bird{
fly(){
throw new
UnsupportedOperationException();
}
}
With “L”
class Bird {
void eat(){}
}
class FlightBird extends Bird {
void fly(){}
}
class NonFlightBird extends Bird {}
class Sparrow extends FlightBird {}
class Ostrich extends NonFlightBird {}
Example of Interface segregation principle
Without “I”
interface IUser{
changePassword();
checkUserRole();
assignRole();
}
With “I”
interface IUser{
changePassword();
}
interface IRole{
assignRole();
}
interface IUserRole{
checkUserRole();
}
Example of Dependency inversion principle
Without “D”
Class Payments {
CreditCardPaymentMethod ccpm = new
CreditCardPaymentMethod();
void makePayments(){
ccpm.transact();
}
With “D”
Class Payments {
PaymentMethod pm;
Payments(PaymentMethod pm_provided) {
pm = pm_provided;
}
void makePayments(){
pm.transact();
}
Q & A

More Related Content

Similar to Solid design principles

AngularJS Curriculum-Zeolearn
AngularJS Curriculum-ZeolearnAngularJS Curriculum-Zeolearn
AngularJS Curriculum-Zeolearn
Hamdi Ceylan
 
10 ap week 7 vbnet statements-genesis eugenio
10 ap week 7 vbnet statements-genesis eugenio10 ap week 7 vbnet statements-genesis eugenio
10 ap week 7 vbnet statements-genesis eugenio
DaniloAggabao
 
Solid-Principles
Solid-PrinciplesSolid-Principles
Solid-Principles
Aniket G
 

Similar to Solid design principles (20)

Applied patterns in the project
Applied patterns in the projectApplied patterns in the project
Applied patterns in the project
 
Bdd with Cucumber and Mocha
Bdd with Cucumber and MochaBdd with Cucumber and Mocha
Bdd with Cucumber and Mocha
 
AngularJS Curriculum-Zeolearn
AngularJS Curriculum-ZeolearnAngularJS Curriculum-Zeolearn
AngularJS Curriculum-Zeolearn
 
2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#2009 Dotnet Information Day: More effective c#
2009 Dotnet Information Day: More effective c#
 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance test
 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
 
Microservices Primer for Monolithic Devs
Microservices Primer for Monolithic DevsMicroservices Primer for Monolithic Devs
Microservices Primer for Monolithic Devs
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
10 ap week 7 vbnet statements-genesis eugenio
10 ap week 7 vbnet statements-genesis eugenio10 ap week 7 vbnet statements-genesis eugenio
10 ap week 7 vbnet statements-genesis eugenio
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
Software Architecture Taxonomies - modularity
Software Architecture Taxonomies - modularitySoftware Architecture Taxonomies - modularity
Software Architecture Taxonomies - modularity
 
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
 
Solid presentation yo
Solid presentation yoSolid presentation yo
Solid presentation yo
 
The good, the bad and the SOLID
The good, the bad and the SOLIDThe good, the bad and the SOLID
The good, the bad and the SOLID
 
Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
 
Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014
 
Solid-Principles
Solid-PrinciplesSolid-Principles
Solid-Principles
 
Design principles - SOLID
Design principles - SOLIDDesign principles - SOLID
Design principles - SOLID
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
 

Recently uploaded

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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
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
 
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...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 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
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Solid design principles

  • 3. History ● 80% of software projects fails ● The theory of SOLID principles was introduced by Robert C. Martin in his 2000 paper “Design Principles and Design Patterns” ● The SOLID acronym itself was introduced later by Michael Feathers
  • 4. Definition ● Single responsibility principle A class should have only a single responsibility (i.e. changes to only one part of the software's specification should be able to affect the specification of the class). ● Open/closed principle "software entities … should be open for extension, but closed for modification." ● Liskov substitution principle "objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program." ● Interface segregation principle "many client-specific interfaces are better than one general-purpose interface.” ● Dependency inversion principle one should "depend upon abstractions, [not] concretions."
  • 5. Example of Single responsibility principle Without “S” class UserService { void changePassword(User user) { if(checkAccess(user)) { //Grant option to change } } boolean checkAccess(User user) { //Verify if the user is valid. } } With “S” class UserService { void changePassword(User user) { if(SecurityService.checkAccess(user)) { //Grant option to change } } } class SecurityService { static boolean checkAccess(User user) { //check the access. } }
  • 6. Example of Open/closed principle Without “O” class LoanApprovalHandler { void approve(PersonalLoanValidator validator) { if ( validator.isValid()) { //Process the loan. } } } class PersonalLoanValidator { boolean isValid() { //Validation logic } } With “O” interface Validator {boolean isValid();} class PersonalLoanValidator implements Validator { boolean isValid() {} } class HomeLoanValidator implements Validator { boolean isValid() {} } class LoanApprovalHandler { void approve(Validator validator) { if ( validator.isValid()) { //Process the loan. } } }
  • 7. Example of Liskov substitution principle Without “L” class Bird { public void fly(){} public void eat(){} } class Sparrow extends Bird {} class Ostrich extends Bird{ fly(){ throw new UnsupportedOperationException(); } } With “L” class Bird { void eat(){} } class FlightBird extends Bird { void fly(){} } class NonFlightBird extends Bird {} class Sparrow extends FlightBird {} class Ostrich extends NonFlightBird {}
  • 8. Example of Interface segregation principle Without “I” interface IUser{ changePassword(); checkUserRole(); assignRole(); } With “I” interface IUser{ changePassword(); } interface IRole{ assignRole(); } interface IUserRole{ checkUserRole(); }
  • 9. Example of Dependency inversion principle Without “D” Class Payments { CreditCardPaymentMethod ccpm = new CreditCardPaymentMethod(); void makePayments(){ ccpm.transact(); } With “D” Class Payments { PaymentMethod pm; Payments(PaymentMethod pm_provided) { pm = pm_provided; } void makePayments(){ pm.transact(); }
  • 10. Q & A