Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Refactor method calls or not?

by trs80 (Priest)
on Jan 19, 2002 at 05:56 UTC ( #140025=note: print w/replies, xml ) Need Help??


in reply to Refactor method calls or not?

I am going to advocate for creating each method name explicit
for the reason of future change. If you find that method
needs to be changed it will already physically exist and
you will just have to modify it. Now I know it isn't a big deal
to add a method in the future, but if you can do it at this
stage I think you will further ahead in the long run.
I think AUTOLOAD is a bad way to go on this one. I had
a discussion with some other proprammers recently about
using AUTOLOAD on something similar and it frowned upon
for maintenance and speed issues.
If there is code already using these methods I would also
suggest code like this:
sub add_company { my ($self,$data) = shift; $self->gen_add($data,'company'); } sub add_financial_diary { my ($self,$data) = shift; $self->gen_add($data,'financialDiary'); } sub gen_add { my ($self,$data,$table) = @_; my $return = $self->_generic_insert( $data, $table ); $self->{ _dbh }->commit if ! $self->{ _error }; return $return; }
This code would allow you move the gen_add method into
another inherited class if you need to and not break the
code. By having $self and $data available you
also cut down on code that needs to be written if you
determine the method needs to not call the gen_add method.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2021-04-23 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?