Search code examples
interfacesolid-principlesliskov-substitution-principleinterface-segregation-principle

The difference between liskov substitution principle and interface segregation principle


Is there any core difference between Liskov Substitution Principle (LSP) and Interface Segregation Principle (ISP)? Ultimately, both are vouching for designing the interface with common functionalities and introduce a new interface when you have special purpose of functionalities.


Solution

  • LSP: The subtype must honor the contracts it promises.

    ISP: The caller shouldn't depend on more of the base type's interface than it needs.

    Where they fit: If you apply the ISP, you use only a slice of the receiver's full interface. But according to LSP, the receiver must still honor that slice.

    If you fail to apply ISP, there can be a temptation to violate LSP. Because "this method doesn't matter, it won't actually be called."