Re: Magic for object constructor wanted
- From: Koszalek Opalek <koszalekopalek@xxxxxxxxxx>
- Date: Thu, 31 Jan 2008 04:49:44 -0800 (PST)
On Jan 31, 8:39 am, Martijn Lievaart <m...@xxxxxxxxxxxxxxxx> wrote:
Sure. Just don't put the objects in separate variables, put them in a
hash.
Even better, bless the hash, iow make it its own class.
Then you get something like:
use Friends;
I'm afraid that misses the point (or I have misunderstood
you). I do not want to bless my objects into Friends.
I want to bless each one into a signle Dude so that I
can do things like
$joe->whoami()
(And I do not want to rewrite code, that takes it for
granted that $joe, $tim, and $ann have all been blessed
into Dude's.)
What you also can do, is store the name of the Dude in the Dude object.
This is better design anyhow, but does not save you the extra redundancy
of specifying the name twice:
my $joe = Dude->new("joe");
my $tom = Dude->new("tom");
my $ann = Dude->new("ann");
my $jane = Dude->new("jane");
That is not different from what I originally
posted except that (name=>"joe") has been
moved from fill() to new().
Koszalek
.
- References:
- Magic for object constructor wanted
- From: Koszalek Opalek
- Re: Magic for object constructor wanted
- From: Martijn Lievaart
- Magic for object constructor wanted
- Prev by Date: Re: "negative" regexp
- Next by Date: how to remove blocks between nested brackets
- Previous by thread: Re: Magic for object constructor wanted
- Next by thread: Re: Magic for object constructor wanted
- Index(es):
Relevant Pages
|