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:

  • 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:

 
Embedded Star Newsletter
Don't have time to visit Embedded Star everyday? Then sign up for our free newsletter. We'll send you an email when we have something to share with you. Your email address will be kept confidential and we will not share, sell, or rent it to anyone. You can unsubscribe at any time by clicking a link in the email.

Enter your email address to sign up for our free newsletter:   

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.