The concept of a factory class makes sense in statically typed languages like Java, where there may be multiple implementations of an interface and you want to hide the process of picking and instantiating an implementation of the interface in such a factory. In Perl, classes can take whatever arguments and return whatever values they please, so this concern applies less often. This means one should spend a little more time thinking about a useful and extensible API and class hierarchy, but I think one has to worry less about the implementation :-) In your case, either of the APIs you showed seems fine to me, however:

since its essentially a factory returning objects of it's own class

I don't see how this follows from your description or code - why would a factory return objects of its own class? Why shouldn't the factory return objects of a different class?


In reply to Re: Using a factory class to return objects of the same class by haukex
in thread 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.