Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: When are packages the right design choice?

by Abigail-II (Bishop)
on Jun 04, 2004 at 08:09 UTC ( [id://360759]=note: print w/replies, xml ) Need Help??


in reply to Re^2: When are packages the right design choice?
in thread When are packages the right design choice?

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.

Log In?
Username:
Password:

What's my password?
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 chanting in the Monastery: (1)
As of 2024-04-18 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found