Page 1 of 1

html presentation without getters

Posted: Sun Aug 02, 2009 2:33 pm
by koen.h
I know at least some of you know this article:

http://www.javaworld.com/javaworld/jw-0 ... olbox.html

It's all convincing. Until you come at the point where Listing 4 is presented: an HTML representation of the Employee without exposing internals.
To improve that class HTMLExporter, I see one solution: a template for the employee (variables filled in by the HTMLExporter) and added to the main template.

Do any of you know alternatives?

Re: html presentation without getters

Posted: Mon Aug 03, 2009 8:57 am
by inghamn
To me, this seems like complexity for complexity's sake. Templating is a much easier way to edit the output format. Examples like this are (rightly) concerned about the business logic and/or business data changing over time. But they never seem to take into account the needs of the output format changing. In my experience, the display or output format changes a whole lot faster and a whole lot more often than the business logic/data. If you're shooting for saving time, it's the display side that you get the most time savings.

If you're doing Templating, the templates must:
a. know what property values they want to display
and
b. assume that those property values are actually availble in the object passed to them.

The article doesn't actually, do templating, though. Holub goes the harder route and creates go-between builder objects that do a bunch of print commands.

Re: html presentation without getters

Posted: Mon Aug 03, 2009 9:38 am
by koen.h
inghamn wrote: If you're doing Templating, the templates must:
a. know what property values they want to display
and
b. assume that those property values are actually availble in the object passed to them.
Maybe one could argue that the template is a part of the builder. Depending on the request (containing the output format) the controller determines what builder to use for each of the domain objects.

Eg: http://mysite/blog/post22/
->no explicit output format, default html
->controller asks SiteModel to display itself using HtmlBuilder
-HtmlBuilder asks SiteModel to add variables to it
-HtmlBuilder looks for html template specific for SiteModel or fall back to default one
->controller asks BlogPostModel to display itself using HtmlBuilder
-same steps

Re: html presentation without getters

Posted: Mon Aug 03, 2009 10:34 am
by inghamn
I can certainly see this technique working. I'm just hard-pressed to image a web development scenario where this technique would solve an existing problem.

Re: html presentation without getters

Posted: Mon Aug 03, 2009 11:19 am
by koen.h
inghamn wrote:I can certainly see this technique working. I'm just hard-pressed to image a web development scenario where this technique would solve an existing problem.
The problem would be 'how not to expose internals to a UI'. I don't think there needs to be more to it than that.

Re: html presentation without getters

Posted: Mon Aug 03, 2009 11:45 pm
by Christopher
I think the point of a template, especially PHP templates, is that they don't expose the internals of the Model. The are dependent on the interface of the Model. And though that may be some getters, hopefully is it higher level data access methods that provides derived or computed values, sorted lists, etc.

Re: html presentation without getters

Posted: Thu Aug 06, 2009 4:48 pm
by josh
View helpers. If you have something repetitive like outputting an address, apply a "preserve whole object" refactoring and make a view helper that decides how to render that object, tada.