in reply to Re^3: Skipping the middle man & the SUPER gotcha
in thread Skipping the middle man & the SUPER gotcha
It's useful when you have multiple-inheritance, to say which of your parent classes to start searching.
Ah, of course, that make a lot of sense.
It's also useful when SUPER:: would be wrong... like a flyweight class.
I'm still scratching my head about this one. This is partly because I have not yet fully grokked Class::Prototyped (but I'm getting there :-) ), but partly because for the longest time I thougth that by "wrong" you meant bad OO design (and for the life of me I couldn't, and still can't, think of any scenario in which it would be OK design-wise to use $me->Dad::hello() but at the same time not OK to use $me->SUPER::hello()). Then it finally hit me that (maybe!) by "wrong" you meant "semantically wrong", as when the code in package main contains the expression $me->SUPER::hello() intending to access the hello method of $me's parent class. With "package-less classes" as those created with Class::Prototyped, there would not be any scope in which the SUPER pseudo-class had the desired meaning.
So at least that explains (maybe) why SUPER is particularly problematic with classes/prototypes created with Class::Protoyped. But what I still can't understand is how the fact that Perl allows the $object->ParentClass::method() form can be of any help if such a class wanted to invoke a method in a parent class. For example (adapted from the Class::Prototyped docs):
How can anything having the form $object->ParentClass::method() be used the definition of $Me's hello?use strict; use Class::Prototyped ':EZACCESS'; my $Dad = Class::Prototyped->new( hello => sub { print "Hiya from $Dad!\n" } ); my $Me = Class::Prototyped::new( 'parent*' => $Dad hello => sub { # ??? print "I'm just a WILD AND CRAZY GUY!\n"; } );
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Skipping the middle man & the SUPER gotcha
by merlyn (Sage) on Apr 03, 2005 at 03:40 UTC |