go ahead... be a heretic PerlMonks

### Re: When are packages the right design choice?

by Abigail-II (Bishop)
 on Jun 04, 2004 at 08:09 UTC Need Help??

I worked hard to avoid using "a square ISA rectangle" type examples in my book.

And that while that's a great example to explain why MI is so useful. A square is both a rectangle and a rhombus, but a rectangle that isn't a square isn't a rhombus, and a rhombus that doesn't have square corners isn't a rectangle. And both a rhombus and a rectangle are parallelograms.

Abigail

• Comment on Re: When are packages the right design choice?

Replies are listed 'Best First'.
Re^2: When are packages the right design choice?
by bl0rf (Pilgrim) on Jun 04, 2004 at 16:51 UTC
That sentence just about sums up why I try to minimize on inheritance :-)
Re^2: When are packages the right design choice?
by kragen (Sexton) on Jun 05, 2004 at 00:11 UTC
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.

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.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://360759]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 23:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found