Liskov Substitution Principle <ul>Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T. </ul>
Liskov Substitution Principle <ul><li>Functions that use references to base classes must be able to use objects of derived classes without knowing it.
Used when inheritance was a main form of reuse.
Design smell – Type checking in client code and changing the behavior for a specific type in client.
Due to forcing an unrelated object into an inheritance hierarchy
Prefer composition over inheritance whenever possible </li></ul>
LSP Violation Data Extractor CSV Format JSON Format Data Extractor Service Reporter (UI + Formatter) Database New Requirement - Adding Database as a data source for report data. Adding it to File Reader Service as it is conveniently there
Better design confirming to LSP File Reader CSV File JSON File File Data Extractor Service Reporter (UI + Formatter) Database Database Data Extractor Service Keep Database separate as it doesn't fit in File Data Extractor Service
Interface Segregation Principle <ul><li>Clients should not be forced to depend on interface they don't use. </li></ul><ul><li>Make fine grained interfaces that are client specific or clients should not be forced to implement interfaces they don't need
Design smell – NotImplementException thrown for some methods (which are really not needed by the client)
Flat and non cohesive interface problem - SRP?
Role based interface design – Intent Revealing Interfaces by Udi Dahan ( IExtractReportData ) </li></ul>
DIP Violation Stuck with Text Format and Text Report Formatter implementations !!! Arrows are Dependency Text Report Formatter Reporting App Text Format JSON Format
Fixing for DIP Text Report Formatter Reporting App CSV Format JSON Format IFormatReport IExtractReportData
Design confirming to DIP IExtractReportData CSV Data Extractor JSON Data Extractor Data Extractor Service Reporter Writer Database Reader Service XML Data Extractor Reporting Application Report Data
Credits <ul><li>SOLID Motivational Posters, by Derick Bailey, is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
Uncle Bob for consolidating these principles and his books Agile Software Development: Principles, Practices and Patterns and Clean Code
Presentation is under Creative Commons Attribution-Share Alike 2.5 India License </li></ul>
About Me <ul><li>Developer in Test at Thoughtworks