http://qs1969.pair.com?node_id=314449

rkg has asked for the wisdom of the Perl Monks concerning the following question:

Hi, all -

A basic OO question involving separating data from presentation:

I am trying to work out an object hierarchy for a reporting system. I am envisioning a base Report class which is subclassed into various forms of displaying the report, such as HTMLReport, PDFReport, ExcelReport, etc.

I'll have several report objects -- RevenueReport, ReceivablesReport, etc which will take parameters on creation indicating geography, time period, etc.

Here's my question: how do I tell a report (say, an instance of RevenueReport) to render as, for example, an HTMLReport? Creating all the combinations explicitly (RevenueHTMLReport, RevenueExcelReport, etc) is clear code-stink.

On the other hand, passing the render type into the report  my $report = SalesReport->new(%args, type=>'HTMLReport') and then making this SalesReport an HTMLReport by pushing 'HTMLReport' onto its ISA array seems even worse.

So I want to separate data from presentation...

so what is the correct way to tell my data object how it should present itself?

Many thanks for clarifying this for me --

rkg