« 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 ;)

The comments to this entry are closed.