Implementing an Output Renderer Strategy

October 02, 2005 13:47, contributed by: demian

An interesting design problem became apparent when a number of folks from the seagull ML recently complained about the lack of support for web clients other than standard browsers. Because the code enforces reasonable segregation between the domain modelling and the html views, I always presumed it would be trivial to implement, ie, an xml renderer instead of the current Flexy to handle WML output. Two problems needed to be solved:

  1. the Flexy renderer was hard-coded in the final stage of a validate/process/display workflow
  2. worse, a number of post-processing tasks, mainly assembling of blocks and building of main navigation were also hard-coded

In short, the process was quite tied to producing HTML-only output, clearly n blocks and involved navigation were unsuitable for PDA output.

I identified two main refactorings necessary to decouple the view production from the output type and specific renderer used, thereby opening the door to running customised post-process tasks based on the current rendering strategy.

To allow an arbitrary renderer to be specified at runtime I chose to compose the View object with a OutputRendererStrategy. This means if you're happy with Flexy you can use the standard renderer supplied with the package, and if you can't bear the thought of working without Smarty, it'd be a piece of cake to write a SmartyOutputRenderStrategy following the Flexy example. The code would look something like this:

    //  build view
$view = new SGL_HtmlView($output, new SGL_HtmlFlexyRendererStrategy());
echo $view->render();

where the $output object is just a php data structure free of any presentation information. The next problem was more interesting, how does producing output for portable devices change the appliation requirements. The basic data structure sent to the view is similar, but the following main differences are evident:

  • any paginated lists sent to the template needed to be a lot shorter, with simpler paging
  • any superfluous info like that found in left/right column blocks had to go
  • navigation had to be dramatically simplified

Using the View type but switching implementation as runtime made it very easy to achieve this, where WmlView implements specialised minimalist post processing tasks, and uses an xlst renderer to output WML. The code would look like this:

    //  build view
$view = new SGL_WmlView($output, new SGL_XmlRendererStrategy());
echo $view->render();

The code is currently only in svn but will make it out in the 0.5.1 devel release planned shortly. The following UML summarises the idea:

[back to list]

comments


be the first to leave a comment
Enter your comment Note: Comments must be approved before being displayed.
   #     #####    #####    #####  
  ##    #     #  #     #  #     # 
 # #          #  #     #  #     # 
   #     #####    ######   #####  
   #    #              #  #     # 
   #    #        #     #  #     # 
 #####  #######   #####    #####  
 

At a Glance

Sponsors

  • Get programming homework help from professionals at Homework-Desk.com anytime!
  • HomeworkPal.com - homework help with biology, physics, math assignments.
  • Having problems with your assignment? Our homework help site can give you a hand with math, physics, programming and much more!
  • Free Usenet Trial
  • ecommerce website new zealand

Login

Username Password

Not Registered?
Forgot Your Password

*denotes required field

Community

 
Seagull PHP Framework

Sponsored by

The Seagull project is sponsored by Seagull Systems, see the range of products offered.

Readers