[Pdx-pm] [build in defaults to method calls from the outside] need some help thinking thru this one

A. Pagaltzis pagaltzis at gmx.de
Wed Jul 25 07:37:37 PDT 2007


* benh <ben.hengst at gmail.com> [2007-07-24 02:30]:
> The problem that I can't cleanly subclass BookInfo, because I
> already know my isbn, so I'm running in to is I keep haveing
> stubs that just pass thru to BookInfo in SingleBook. About
> 2/3's of SingleBook is basicly
> 
> sub do_something {
>    my ( $self ) = @_;
>    return $self->{bi}->do_something($self->{isbn});
> }

If you are passing the same parameter to all of the methods of an
object, then that parameter should really be a field on that
object. Or on some other object, depending on the requirements.
If that doesn’t seem viable, that basically means your OO design
is clumsy.

You can work around this with things like AUTOLOAD et al, but I’d
try to tackle it on a more fundamental level. If you explain more
about your class hierarchy and why you chose things the way you
did, someone might be able to propose a better layout.

> It works, but it seems needlessly messy.

Now that’s a classic if I ever heard one. :-)

If you find yourself saying something this, you should
immediately suspect an XY problem.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>


More information about the Pdx-pm-list mailing list