Exforsys

Online Training

Render yourself ou ask someone else to render you?

This is a discussion on Render yourself ou ask someone else to render you? within the Software Patterns forums, part of the Testing category; Hi, Here is a quick OO design question. Suppose I have a few objects that I would want rendered in ...


Go Back   Exforsys > Testing > Software Patterns

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-14-2005, 01:27 AM
vincent.bouret@gmail.com
Guest
 
Posts: n/a
Render yourself ou ask someone else to render you?

Hi,

Here is a quick OO design question. Suppose I have a few objects that I
would want rendered in HTML (Article, Category). What would be the best
OO way to render them? (BTW, the language is PHP)

If I am not mistaken,

1) the Strategy pattern would instruct me to pass the rendering to
another object. So I would have HTMLArticleRenderer that is constructed
using an Article object and that will render using
HTMLArticleRenderer->render(). If I wanted to add a PDF output, I could
just add a PDFArticleRenderer and switch renderer at runtime.

2) the Decorator pattern would instruct me to add a render() method to
every object (Article, Category) so they could be called in a tree-like
fashion.

I want your opinion on which would be the best solution or the
cleanest?

Regards,

Vincent

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-14-2005, 06:34 PM
Oliver Wong
Guest
 
Posts: n/a
Re: Render yourself ou ask someone else to render you?


<vincent.bouret@gmail.com> wrote in message
news:1134538032.486439.26380@f14g2000cwb.googlegroups.com...
> Hi,
>
> Here is a quick OO design question. Suppose I have a few objects that I
> would want rendered in HTML (Article, Category). What would be the best
> OO way to render them? (BTW, the language is PHP)
>
> If I am not mistaken,
>
> 1) the Strategy pattern would instruct me to pass the rendering to
> another object. So I would have HTMLArticleRenderer that is constructed
> using an Article object and that will render using
> HTMLArticleRenderer->render(). If I wanted to add a PDF output, I could
> just add a PDFArticleRenderer and switch renderer at runtime.
>
> 2) the Decorator pattern would instruct me to add a render() method to
> every object (Article, Category) so they could be called in a tree-like
> fashion.
>
> I want your opinion on which would be the best solution or the
> cleanest?


I believe web applications are generally written using the Model View
Controller pattern. It sounds like "Article" is your model, and so you need
to create a View; e.g. "HTMLView" or "PDFView" which can receive an article
and generate and HTML or PDF representation of it.

That's closer to your (1) than your (2), I think.

- Oliver


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-27-2005, 02:29 PM
pitdog@gmail.com
Guest
 
Posts: n/a
Re: Render yourself ou ask someone else to render you?

I would use a strategy for this based on what you have stated.
Based on the limited detail you gave a and about 3 mins to think about
it I would do something like this.

1.Create a abstract class or an interface called IRenderable.
2.Implement the base level impl or create the public interface that all
things that need to have to be rendered.
3.Implement your concrete classes that either inherit from this base or
implement the interface. (I.E. Strategy)
4.Create a class to render anything the implements or inherits
IRenderable.

This can still be done using a Model View Controller and in fact it can
help you in writing less view code if your your Model is a IRenderable
object or a IRenderable collection all you would need is one View page
to render anything that is IRenderable.


Just my 4 cents.

PitDog

Oliver Wong wrote:
> <vincent.bouret@gmail.com> wrote in message
> news:1134538032.486439.26380@f14g2000cwb.googlegroups.com...
> > Hi,
> >
> > Here is a quick OO design question. Suppose I have a few objects that I
> > would want rendered in HTML (Article, Category). What would be the best
> > OO way to render them? (BTW, the language is PHP)
> >
> > If I am not mistaken,
> >
> > 1) the Strategy pattern would instruct me to pass the rendering to
> > another object. So I would have HTMLArticleRenderer that is constructed
> > using an Article object and that will render using
> > HTMLArticleRenderer->render(). If I wanted to add a PDF output, I could
> > just add a PDFArticleRenderer and switch renderer at runtime.
> >
> > 2) the Decorator pattern would instruct me to add a render() method to
> > every object (Article, Category) so they could be called in a tree-like
> > fashion.
> >
> > I want your opinion on which would be the best solution or the
> > cleanest?

>
> I believe web applications are generally written using the Model View
> Controller pattern. It sounds like "Article" is your model, and so you need
> to create a View; e.g. "HTMLView" or "PDFView" which can receive an article
> and generate and HTML or PDF representation of it.
>
> That's closer to your (1) than your (2), I think.
>
> - Oliver


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 11:08 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.