Re:Circle-Ellipse Problem
by Groxx on Sunday April 17, 2011 @03:15PM
(#2456742)
I think the main problem here is that OO "is-a" isn't the same thing as mathematical "is-a". A square is a rectangle, but a square cannot perform every action a rectangle can.
In the ass-backwards mutable-OO world, a rectangle "is-a" square, because it can be a square. Under the same requirements (x==y), a rectangle is a square. Any action which acts on a square will do precisely the same thing with a square rectangle which inherits from a square.
Similarly, a get-bounding-box for a rectangle inheriting from a square must always return a square box - a get-bounding-rectangle method must be created to handle the new, non-square output.
Rectangles supercede squares in every way, therefore a rectangle is-a square, and it is more. The mathematical "is-a" is essentially the reverse of this - a square is a rectangle with restrictions.
In the ass-backwards mutable-OO world, a rectangle "is-a" square, because it can be a square. Under the same requirements (x==y), a rectangle is a square. Any action which acts on a square will do precisely the same thing with a square rectangle which inherits from a square.
Similarly, a get-bounding-box for a rectangle inheriting from a square must always return a square box - a get-bounding-rectangle method must be created to handle the new, non-square output.
Rectangles supercede squares in every way, therefore a rectangle is-a square, and it is more. The mathematical "is-a" is essentially the reverse of this - a square is a rectangle with restrictions.