« Quest for Speed - Moore's Law. | Main | Should Interfaces Declare Constants (Java) ? »

03/16/2012

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Sai Matam

I totally agree that Liskov substitution principle should be respected. I am planning to write another blog-post on 'Design by contract'. In that I plan to discuss Liskov's principle.

wit

When defining your class relationships, the "is-a" rule is not enough, you have to ensure that Liskov substitution principle is respected.

See http://en.wikipedia.org/wiki/Liskov_substitution_principle

For example, a square is-a rectangle, but a square doesn't behave as a rectangle, because you cannot modify its length without modifying its height with the same amount (else it wouldn't stay a square) as you would do with a rectangle (setLength() and setHeight()).

Defining an inheritance relationship between a Rectangle parent class and a Square child class could then be totally incorrect, although the "is-a" rule of thumb seems right.

Srikanth Ganapavarapu

Great example and wonderfully articulated.

Yannick

Both can be instantiated, by Chuck Norris ;)

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)