juan_gandhi: (Default)
[personal profile] juan_gandhi
It's a known puzzle from the depths of object-oriented teaching: is Circle a subclass or Ellipse. From school we know it is; but as we read in books, for programmers, it is not. How come? Oh, "Liskov principle". They use Liskov principle to scare kids.

Actually we know that a circle is an ellipse with both axes being the same length.

But in programming, an ellipse is something different. It is at least stretchable. And it is also moveable. Somehow it is not rotatable, but we can skip it for simplicity.

An ellipse in programming is (almost) always horizontal; it can be moved (by changing coordinates of its center) and it can be stretched/compressed by changing its height and width. Sure a stretchable ellipse is neither an ellipse nor a circle, not even a stretchable circle. A stretchable circle stretches equally in all directions.

That's it, no? Questions? Objections?

Date: 2011-01-24 08:07 pm (UTC)
stas: (Default)
From: [personal profile] stas
"is a" in the language is quite informal - when they say "pessimist is a well-informed optimist", they don't mean pessimist-optimist relationship should follow the LSP.

BTW, when I was a kid, I was being scared by sqare-rectangle example, not circle-ellipse.

"pessimist is a well-informed optimist"

Date: 2011-01-24 08:27 pm (UTC)
From: [identity profile] alextr98.livejournal.com
optimist is a well-instructed pessimist!

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

December 2025

S M T W T F S
  1 2 3 4 56
7 89101112 13
14 151617 181920
21222324252627
28293031   

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 20th, 2025 01:38 pm
Powered by Dreamwidth Studios