Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: OO Design -- Separating Data from Presentation

by adrianh (Chancellor)
on Dec 13, 2003 at 02:26 UTC ( [id://314453]=note: print w/replies, xml ) Need Help??


in reply to OO Design -- Separating Data from Presentation

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

Of course there is never the correct way :-)

However, it might help to split the functionality into three layers:

  1. Reports - to handle the details of the different report types (RevenueReport, SalesReport, etc.)
  2. ReportFormatters - take report objects and provide a format-independent API to their structure (e.g. $rf->header, $rf->content, etc.)
  3. ReportRenderers - that take a ReportFormat object and output it in a particular format (ReportRenderPDF, ReportRenderHTML, etc.)

So all the report specific information stays in the Report class. All the output-format specific information stays in the ReportRender classes.

Hopefully this makes some sort of vague sense :-)


Update: Just noticed - this was my 1000th post. Gosh.

  • Comment on Re: OO Design -- Separating Data from Presentation

Replies are listed 'Best First'.
Re: Re: OO Design -- Separating Data from Presentation
by rkg (Hermit) on Dec 14, 2003 at 01:33 UTC
    Many thanks, adrianh. I was hung up on asking the Report to render itself, rather than passing the Report object to a ReportRenderer object. Your answer was spot-on, and got me thinking about objects of the form Noun-That-Does-Verb... interesting... makes me think of a gerund in English. Cool. Thanks --

    rkg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://314453]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-20 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found