Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Re: Re: Overloading inherited class methods

by Ovid (Cardinal)
on Dec 04, 2002 at 19:11 UTC ( [id://217563]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Overloading inherited class methods
in thread Overloading inherited class methods

It was a problem here, but it may not have been completely obvious because I decided not to post the entire code of the superclass. However, the problem lies in issues like this:

  my ($class, %args) = @_;

If that occurs, I might append extra data to %args that does not logically belong there in all cases. However, if I convert %args to a reference, I can keep my "extra" info seperate and I don't have to build as many special cases in my code to account for the extra hash keys:

  my ($class, $args, $id) = @_;

(That's just an example, but you get the idea.) My problem lay in the fact that the subclassed constructor was expecting a single scalar id, which, if I passed the %args has from the get_list method, then the first element gets assigned to $id. Now, on second thought, I can see an error I made. I don't need to pass %args because the constructor already knows about it. Hmm... more work to do. Should take another two minutes :)

Update: Took me less than two minutes, actually. Now my methods in the subclass look like this:

sub new { my ($class,$id) = @_; $class->SUPER::new( %ARGS, open_id => $id ); } sub get_list { my $class = shift; $class->SUPER::get_list( %ARGS ); }

I am wondering now what would happen if I moved those into the superclass and exported them into subclasses (would that work? Then I wouldn't need to keep rewriting those methods for every class. I would just need to provide the %ARGS hash for configuration information and most objects would then simply use the superclass and have most of their methods just work. Interesting thought.

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://217563]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found