SlideShare ist ein Scribd-Unternehmen logo
1 von 13
SOLID Principles - II
LSP – Liskov Substitution Principle
ISP – Interface Segregation Principle
Maulik Soni
Liskov Substitution Principle
 Subtypes must be substitutable for their base types.
Maulik Soni
Is LSP Violated Here ?
Maulik Soni
How To Spot LSP Violation ?
 Derivative that tries to do less than base class
 Instance of checks
 Hiding or stubbing parent methods
 Void SomeMethod(){}
 Void SomeMethod(){ Throw new ShouldNotBecalledException(“…”);}
 Polymorphic if Statements
Maulik Soni
Resolution
Maulik Soni
Interface Segregation Principle
 Client should not be forced to depend on methods they do not use
Maulik Soni
Why ISP Important ?
 Each member of an interface needs to be implemented in its entirety
 Properties
 Events
 Methods
 Unless every client of an interface requires every member
 It does not make sense to force client to implement such a large contract
Maulik Soni
Example
Maulik Soni
Software
Is ISP Violated Here?
Maulik Soni
Resolution
Maulik Soni
Re-Visit the solution
Maulik Soni
Software
IPrint IScan IFax
IPrint
IScan
IFax IPrint
IScan
IStaple
Summary
 Design cohesive interfaces and avoid “fat” interfaces
 The dependency of one class to another should depend on the smallest possible interface
 The interface of the class can be broken up into groups of methods
 Each group serves a different set of clients
 Check Classes with a high number of Public methods
 Group clients according to their calls to the public methods
 Check for methods that frequently change together
Maulik Soni
End of Presentation
Maulik Soni

Weitere ähnliche Inhalte

Ähnlich wie SOLID Principles Part 2

Design Patterns: From STUPID to SOLID code
Design Patterns: From STUPID to SOLID codeDesign Patterns: From STUPID to SOLID code
Design Patterns: From STUPID to SOLID codePaulo Gandra de Sousa
 
SOLID principles-Present
SOLID principles-PresentSOLID principles-Present
SOLID principles-PresentQuang Nguyen
 
Inversion of Control
Inversion of ControlInversion of Control
Inversion of ControlShuhab Tariq
 
Is your code solid
Is your code solidIs your code solid
Is your code solidNathan Gloyn
 
Software Design Principles
Software Design PrinciplesSoftware Design Principles
Software Design PrinciplesOcean Dong
 
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)Simone Chiaretta
 
Service Actions
Service ActionsService Actions
Service ActionsOutSystems
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patternsPrabhakar Sharma
 
Framework Engineering 2.1
Framework Engineering 2.1Framework Engineering 2.1
Framework Engineering 2.1YoungSu Son
 
Interface segregation principle
Interface segregation principleInterface segregation principle
Interface segregation principlemuhammadali0014
 
Transaction Control – a Functional Approach to Modular Transaction Management...
Transaction Control – a Functional Approach to Modular Transaction Management...Transaction Control – a Functional Approach to Modular Transaction Management...
Transaction Control – a Functional Approach to Modular Transaction Management...mfrancis
 
Solid design principles
Solid design principlesSolid design principles
Solid design principlesMahmoud Asadi
 
There are only 3 operations in a web app
There are only 3 operations in a web appThere are only 3 operations in a web app
There are only 3 operations in a web appSimon Smith
 
Service oriented component model
Service oriented component modelService oriented component model
Service oriented component modelravindrareddy
 
Writing Maintainable Software Using SOLID Principles
Writing Maintainable Software Using SOLID PrinciplesWriting Maintainable Software Using SOLID Principles
Writing Maintainable Software Using SOLID PrinciplesDoug Jones
 
OO design principles & heuristics
OO design principles & heuristicsOO design principles & heuristics
OO design principles & heuristicsDhaval Shah
 
A Tale of Contemporary Software
A Tale of Contemporary SoftwareA Tale of Contemporary Software
A Tale of Contemporary SoftwareYun Zhi Lin
 

Ähnlich wie SOLID Principles Part 2 (20)

Design Patterns: From STUPID to SOLID code
Design Patterns: From STUPID to SOLID codeDesign Patterns: From STUPID to SOLID code
Design Patterns: From STUPID to SOLID code
 
Python SOLID
Python SOLIDPython SOLID
Python SOLID
 
SOLID principles-Present
SOLID principles-PresentSOLID principles-Present
SOLID principles-Present
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Inversion of Control
Inversion of ControlInversion of Control
Inversion of Control
 
Is your code solid
Is your code solidIs your code solid
Is your code solid
 
Software Design Principles
Software Design PrinciplesSoftware Design Principles
Software Design Principles
 
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)
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Service Actions
Service ActionsService Actions
Service Actions
 
Design principle vs design patterns
Design principle vs design patternsDesign principle vs design patterns
Design principle vs design patterns
 
Framework Engineering 2.1
Framework Engineering 2.1Framework Engineering 2.1
Framework Engineering 2.1
 
Interface segregation principle
Interface segregation principleInterface segregation principle
Interface segregation principle
 
Transaction Control – a Functional Approach to Modular Transaction Management...
Transaction Control – a Functional Approach to Modular Transaction Management...Transaction Control – a Functional Approach to Modular Transaction Management...
Transaction Control – a Functional Approach to Modular Transaction Management...
 
Solid design principles
Solid design principlesSolid design principles
Solid design principles
 
There are only 3 operations in a web app
There are only 3 operations in a web appThere are only 3 operations in a web app
There are only 3 operations in a web app
 
Service oriented component model
Service oriented component modelService oriented component model
Service oriented component model
 
Writing Maintainable Software Using SOLID Principles
Writing Maintainable Software Using SOLID PrinciplesWriting Maintainable Software Using SOLID Principles
Writing Maintainable Software Using SOLID Principles
 
OO design principles & heuristics
OO design principles & heuristicsOO design principles & heuristics
OO design principles & heuristics
 
A Tale of Contemporary Software
A Tale of Contemporary SoftwareA Tale of Contemporary Software
A Tale of Contemporary Software
 

Kürzlich hochgeladen

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Kürzlich hochgeladen (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

SOLID Principles Part 2

  • 1. SOLID Principles - II LSP – Liskov Substitution Principle ISP – Interface Segregation Principle Maulik Soni
  • 2. Liskov Substitution Principle  Subtypes must be substitutable for their base types. Maulik Soni
  • 3. Is LSP Violated Here ? Maulik Soni
  • 4. How To Spot LSP Violation ?  Derivative that tries to do less than base class  Instance of checks  Hiding or stubbing parent methods  Void SomeMethod(){}  Void SomeMethod(){ Throw new ShouldNotBecalledException(“…”);}  Polymorphic if Statements Maulik Soni
  • 6. Interface Segregation Principle  Client should not be forced to depend on methods they do not use Maulik Soni
  • 7. Why ISP Important ?  Each member of an interface needs to be implemented in its entirety  Properties  Events  Methods  Unless every client of an interface requires every member  It does not make sense to force client to implement such a large contract Maulik Soni
  • 9. Is ISP Violated Here? Maulik Soni
  • 11. Re-Visit the solution Maulik Soni Software IPrint IScan IFax IPrint IScan IFax IPrint IScan IStaple
  • 12. Summary  Design cohesive interfaces and avoid “fat” interfaces  The dependency of one class to another should depend on the smallest possible interface  The interface of the class can be broken up into groups of methods  Each group serves a different set of clients  Check Classes with a high number of Public methods  Group clients according to their calls to the public methods  Check for methods that frequently change together Maulik Soni

Hinweis der Redaktion

  1. Barbara Liskov wrote this principle in 1988.
  2. Task : Base class Research Task - you can close the task even if it’s started Project : Task Derived class
  3. The Interface is a key tool in the modern object-oriented programmers’ toolkit. Interface represent the boundaries between what client code requires and how that requirement is implemented. The ISP states that interfaces should be small.
  4. The design problem was that a single Job class was used by almost all of the tasks. Whenever a print job or a stapling job needed to be performed, a call was made to the Job class. This resulted in a 'fat' class with multitudes of methods specific to a variety of different clients. Because of this design, a staple job would know about all the methods of the print job, even though there was no use for them.
  5. The solution suggested by Martin utilized what is called the Interface Segregation Principle today. Applied to the Xerox software, an interface layer between the Job class and its clients was added using the Dependency Inversion Principle. Instead of having one large Job class, a Staple Job interface or a Print Job interface was created that would be used by the Staple or Print classes, respectively, calling methods of the Job class. Therefore, one interface was created for each job type, which were all implemented by the Job class.