in reply to Help me understand inheritance please!

Since your object isn't a handy_method, you should consider simply exporting these things instead. ISA is only valid when you really and truely do have the situation where one object is a more specific example of the parent class. You'll probably want to consider using delegation before considering inheritance.
  • Comment on Re: Help me understand inheritance please!

Replies are listed 'Best First'.
Re^2: Help me understand inheritance please!
by jdtoronto (Prior) on Nov 04, 2004 at 18:42 UTC
    Oh yes!

    So you suggest that my 'toolchest' of things be put into a 'normal' module and be imported into the OO module. That makes sense!

    My problem is that I read the book and nod sagely, but when it comes to sitting at the keyboard it doesn't make that much sense any more! Thanks for the clarification.

    jdtoronto

      my 'toolchest' of things be put into a 'normal' module and be imported into the OO module

      Your toolchest doesn't necessarily have to be a procedural ("normal") module, it too can be object oriented. diotalevi is only suggesting that the relationship between your toolchest module and your application module doesn't appear to be one where inheritance is appropriate.

      Inheritance is for when one thing is another thing, where as delegation is when one thing has another thing. These are commonly refered to as is-a and has-a relationships. This is why inheritance in Perl is done through the @ISA array. Delegation in Perl can be accomplished simply by storing one object as an attribute in another object, and calling the first object's methods as appropriate.

      To further reinforce the point, consider describing your situation in these terms. Does it make more sense to say "my application is a toolbox" or "my application has a toolbox"? Compare to a frequent example where inheritance is used: "this cat is a mammal" vs "this cat has a mammal." That should help you decide which is appropriate.

        How do I use the "has-a" relationship? Say I have a paw object that is used by many of my objects, like the cat object. I'd use it like $cat->paw->scratch, but how would cat.pm use implement the paw.pm?

      My problem is that I read the book and nod sagely, but when it comes to sitting at the keyboard it doesn't make that much sense any more!

      Such is the curse of OO design guidelines: putting them into practical use.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.