With all due respect, my initial question has to do with learning about the 'why' of the Orthodox approach. I feel like you have just parroted the orthodoxy right back to me. I am not taking a stand on right vs. wrong, here, but am attempting to learn with good examples and counter-examples.

First off, don't do my $class = ref $class || $class; That is poor style. Ignore the fact that 99% of the known world does it that way. It's nearly always wrong.

So why, other than your opinion, are these things wrong?

I would use a Factory specifically. First off, you keep the knowledge of which classes actually exist in one place. I like manifests. It helps us maintenance programmers immensely. Also, as a maintenance programmer, I don't like dual-use functions. They are confusing. Base classes are meant to be abstract. Factories are meant to churn stuff out. Factories and Base classes aren't the same thing.

The example I gave above keeps the knowledge of which classes actually exist in one place (or, rather, it's certainly a convenient place to keep the knowledge of classes but doesn't mandate that the knowledge be kept there). That was part of my illustration. Your concerns about dual-use functions are fine -- though they don't bother me personally I'm just as happy with separate constructor methods and factory methods. I'm interested in hearing more about why you think they should reside in separate classes, however. I also wonder if you could elaborate on why you think Base classes must be abstract. (or do you mean that you should always start with an interface -- which Perl is not necessarily admirably equipped to handle?)

Just cause you can doesn't mean you should.

This teaches me nothing, but it does repeat the orthodox party line.

Thanks for the response,
Matt


In reply to Re: Re: Constructor/Factory Orthodoxy by mojotoad
in thread Constructor/Factory Orthodoxy by mojotoad

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.