LSP (Liskov Substitution Principle)


lsp Liskov’s notion of a behavioural subtype defines a notion of substitutability for objects; that is, if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program (e.g. correctness).


The LSP principles are followed in the following cases:

  • No new exceptions should be thrown by methods of the subtype, except where those exceptions are themselves subtypes of exceptions thrown by the methods of the supertype.
  • does not violate the functionality
  • returns the same type
  • subclass object has a contract with a superclass

The LSP principle is violated in the following cases:

  • the parent class in the method calls some kind of external service,    and the child completely rewrites the method.

Read More: