The Liskov Substitution Principle

The Liskov Substitution Principle of object oriented design states:

In class hierarchies, it should be possible to treat a specialized object as if it were a base class object.

The basic idea here is very simple. All code operating with a pointer or reference to the base class should be completely transparent to the type of the inherited object. It should be possible to substitute an object of one type with another within the same class hierarchy. Inheriting classes should not perform any actions that will invalidate the assumptions made by the base class.

This is best explained with an example. The following example explains a case where enhancements to the code can violate the Liskov Substitution Principle. The discussion is divided into three steps:

View Entire Paper | Previous Page | White Papers Search

If you found this page useful, bookmark and share it on: