That sentence just about sums up why I try to minimize on inheritance :-) | [reply] |
I don't think that's a good example of MI, and the big problem with "square ISA rectangle" is that it's often exactly backwards. If a square has just a width, but a rectangle has a width and a height, and the rectangle is mutable, then rectangle should be a subclass of square, not the other way around. Otherwise, there's nothing sensible to do if someone calls setHeight on your Square. Again, depending on your application. If you're trying to prove theorems about your geometric objects instead of draw them on the screen, square should indeed be some kind of a specialization of rectangle. | [reply] |
Your post is an excelent example of why inheirtance relationships are so hard to get right (even for this seemingly trivial example). From a Eucldian point of view, a square ISA rectangle. However, in OOP, a subclass is supposed to extend the parent's behavior, so it makes more sense to say a rectangle ISA square. Two groups thus create two opposite designs.
So who is right? It depends on your application. As you say, if this is a program for geometry, it's probably better to say a square ISA rectangle. If it's a CAD program, then it's probably better to say a rectangle ISA square.
----
send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.
| [reply] |