> ...and thought - "why not just install the missing module then?"

because different "missing" modules have different interfaces !

The factory creates objects/classes with the same interface (which might themselves make use of a specialized CPAN module under the hood ... or not)

Example: you create something with a complicated dynamic table, with rows and cells.

Tables with rows and cells are a universal concept, but the details differ a lot.

The factory could produce output-backends for

but all now with the same interface for geometry, color, font, etc.

And just supporting the features you really need for the problem at hand.

The code for the complicated table is just using the factory and doesn't need to care about the output details.

And if someone needs to target new media - like a fancy JS-library for grids - you'll just add an implementation to the factory.

I don't know if that's even possible (or how useful the feasable may be), but it's an example.

Now take a look at all the modules for Tables and ask yourself how you'd write reusable code to use multiple of them.


Part of the problem here is that most of the literature for factory classes will be written with JAVA like languages in mind. Perl is far more TIMTOWTDI.

In Perl I could imagine a factory "package" without any OOP involved.

Or a factory "function" (aka a generator) to create functions. (generators are actually quite common in functional programming but rarely as complex as packages)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

In reply to Re^3: Factory classes in Perl by LanX
in thread Factory classes in Perl by Bod

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, 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, 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.