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 - Liskov Substitution and Interface Segregation

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 - Liskov Substitution and Interface Segregation (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

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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
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
 

Kürzlich hochgeladen (20)

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
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
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
 

SOLID Principles - Liskov Substitution and Interface Segregation

  • 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.