Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
> ...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

  • HTML,
  • TK,
  • Excel,
  • Word,
  • PDF,
  • SVG
  • LaTeX
  • you-name-it,

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":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-06-18 19:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.