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?
html presentation without getters
Moderator: General Moderators
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: html presentation without getters
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.
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
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.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.
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
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: html presentation without getters
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
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.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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: html presentation without getters
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)
Re: html presentation without getters
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.