html presentation without getters

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

html presentation without getters

Post 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?
User avatar
inghamn
Forum Contributor
Posts: 174
Joined: Mon Apr 16, 2007 10:33 am
Location: Bloomington, IN, USA

Re: html presentation without getters

Post 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.
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

Re: html presentation without getters

Post 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
User avatar
inghamn
Forum Contributor
Posts: 174
Joined: Mon Apr 16, 2007 10:33 am
Location: Bloomington, IN, USA

Re: html presentation without getters

Post 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.
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

Re: html presentation without getters

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: html presentation without getters

Post 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.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: html presentation without getters

Post 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.
Post Reply