cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:
I want to create a subclass instance. Intuitively, I want to write it like this:use Class; use Class::SubClass; my $obj = Class->new(...authentication vars...);
while also being able to call it like this:my $subobj = $obj->subclass->new();
Now, I know the former is horrible. It *sort of* works, but it's a cludge. In Class, I need:my $subojb = Class::SubClass->new(...authentication vars...);
sub subclass { my $self = shift; return Class::SubClass->new(%{$self}); }
And then in SubClass, I need to fudge the constructor or at least, that's how I look at it anyway.
Is there a best practice way to do this? I'm probably searching on the wrong term, but I can't seem to get to the meat through the results I find when looking for this.
thoughts?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sub classing best practice
by Fletch (Bishop) on Dec 11, 2006 at 14:21 UTC | |
|
Re: sub classing best practice
by jbert (Priest) on Dec 11, 2006 at 14:33 UTC | |
|
Re: sub classing best practice
by polettix (Vicar) on Dec 11, 2006 at 14:38 UTC | |
by cLive ;-) (Prior) on Dec 11, 2006 at 15:57 UTC | |
by jbert (Priest) on Dec 11, 2006 at 16:12 UTC | |
by Joost (Canon) on Dec 11, 2006 at 16:10 UTC | |
by polettix (Vicar) on Dec 11, 2006 at 16:20 UTC | |
|
Re: sub classing best practice
by Joost (Canon) on Dec 11, 2006 at 16:01 UTC | |
|
Re: sub classing best practice
by ysth (Canon) on Dec 11, 2006 at 16:38 UTC | |
by cLive ;-) (Prior) on Dec 11, 2006 at 18:19 UTC | |
by ysth (Canon) on Dec 12, 2006 at 05:36 UTC |