The Liskov Substitution Principle
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:
- Original Code
- Brand-C Support Code Enhancements
- Problems (Violates Liskov Substitution Principle)
View Entire Paper | Previous Page | White Papers Search
If you found this page useful, bookmark and share it on:
If you are familiar with RSS feeds, you can also sign up for our free blog feed. Our RSS feed is updated in real-time while our newsletter is updated daily.
