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. | [reply] |
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
| [reply] |
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.
| [reply] [d/l] |
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.
| [reply] |
A lot depends on what kind of commonalities you have. If significant portions of the
- interface are similar, you don't have inheritance - you have an API
- functionality are similar, you want to have a utilities module
- functionality and interface are similar, you should consider inheritance from some common base class(es)
A utilities module shouldn't contain any references to the innards of any object. It should literally be a bunch of subs along the lines of:
sub min { $_[0] < $_[1] ? $_[0] : $_[1] }
These are subs that do something useful, but are completely atomic - they don't have any reference points outside themselves.
Now, you mention listcmd and browsecmd. I don't know Tk, but it sounds like they both deal with commands, in some sense. So, maybe you don't actually have inheritance as much as delegation. Have you considered abstracting out some cmd object and having listcmd and browsecmd both contain an instance of cmd?
From what I'm guessing, the list part would be inheritable. So, let's say you had a listfoo and a listbar. You would have a list baseclass that both would inherit from, plus foo and bar classes that they would delegate to.
DOes that make sense?
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] [d/l] |
| [reply] |
Thanks rinceWind,
Another interesting suggestion. By your method I could take my BrowseEntry, wrap it up in a MegaWidget with the code for its associated events (listcmd and browsecmd in this case) and then use it wherever that functionality is needed. That would work, and as I think about it I could pass a coderef into the megawidget for another method that needs to be run whenever a value is selected from the drop-down.
My copy of Steve Lidie's Mastering Perl/Tk is right beside me and is falling apaprt in some places! Almost time to go and buy another.
jdtoronto
| [reply] |
Have you considered using Spiffy (CPAN for it)? | [reply] |