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!


In reply to Using a factory class to return objects of the same class by Amblikai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.