Amblikai has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks!
I have a question which might be considered a "stylistic" issue but i thought i would get some insight.
Essentially i have a class which requires some configuration (read an XML file to decide how to handle incoming data)
Lots of objects are then created of that class using a data structure which can be fairly arbitrary
So basically, i'm musing over the problem of seperating the incoming data with configuration options. Something like
my $obj=class->new({config_file => "file.xml", data => \%some_yummy_da +ta});
Which doesn't seem very elegant to me. So i was thinking of handling it slightly differently:
my $factory=class->new({config_file => "file.xml"}); my $obj=$factory->give_me_my_object(\%data);
But then THAT seems weird since its essentially a factory returning objects of it's own class. And on top of that, it raises questions like what would happen if i tried to access "factory only" methods through the produced objects etc.
Any thoughts? Am i over complicating this?
Thanks as always for any help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using a factory class to return objects of the same class
by haukex (Archbishop) on May 21, 2019 at 15:48 UTC | |
by Amblikai (Scribe) on May 21, 2019 at 16:45 UTC | |
by haukex (Archbishop) on May 21, 2019 at 18:28 UTC | |
by pryrt (Abbot) on May 21, 2019 at 17:00 UTC | |
|
Re: Using a factory class to return objects of the same class
by choroba (Cardinal) on May 21, 2019 at 15:56 UTC | |
by Amblikai (Scribe) on May 21, 2019 at 16:59 UTC | |
by choroba (Cardinal) on May 21, 2019 at 18:53 UTC |