Hi. I’m looking Monk Wisdom on an OO design question.

I have an app that will generate many different matrices. Each cell in a matrix is either a plain scalar, or a scalar with an associated type (link, percentage, money, abbreviation, etc). I want to be able to render these matrices in a different formats: as HTML (thru Template::Toolkit), as an Excel Spreadsheet (thru Spreadsheet::WriteExcel), as flat text file, etc.

How to display a cell will depend on where it is being rendered. For example, a “link” cell should become <a href=FOO>BAR</a> when rendered as HTML, should beome just “BAR” when rendered as an Excel cell or as a text file. For a “percentage”, the scalar should be run thru sprintf for HTML, should be made into real Excel percentage using Excel formats for the spreadsheet, and should be made into a long decimal (0.33333333333) for the flat text file.

I am looking for advice on doing this in an OO way, rather than embedding lots of “if type=bar and outputdest=baz then blah blah” code.

Thanks!

nop

In reply to OO design question by nop

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.