Liskov’s substitution principle

Heuristics and conventions

There are some heuristics that can help you find violations of the Liskov principle. They all have to do with derived classes that somehow remove or corrupt the functionality of the base classes.

Degenerative functions in derivatives

Throw exceptions in derivatives

Another common cause of LSP violation is throwing exceptions in derived classes whose base classes are not thrown. If the users of the base classes do not expect exceptions, adding them will make them non-replaceable.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alexander Urrego

Alexander Urrego

Systems Engineer with a huge experience working on IT infrastructure projects and passionate about software development, AR/VR, Big Data, and Machine Learning.