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