[Nitro] xhtml builder in model?

James Britt james_b at neurogami.com
Tue Sep 6 12:51:13 EDT 2005

George Moschovitis wrote:
> I think you can already do this. If not, we could generalize the
> XhtmlMixin module.
> This is a reasonable request I guess.
> thanks,
> George.
> On 9/6/05, Peter Abrahamsen <rainhead at gmail.com> wrote:
>>Hi all,
>>Why can we only use the XhtmlMixin's build in a controller? I'd
>>really like to be able to use it in a model, so that the model knows
>>how to generate an edit form, not the controller. This means that I
>>can put a form to create a new whatever from anywhere in my site, no
>>matter which is the current controller.

Is this a case, though, of having the model (e.g., that data) getting 
mixed up with the presentation, breaking MVC?

On the other hand, I'm reminded of Allen Holub's articles on doing GUI 
stuff in Java, where he derided getters and setters, and said something 
along the lines of objects should know how to render themselves.



I'll explain the whys and wherefors in a moment, but here are some rules 
of thumb that you can apply to see if you're really looking at an 
object-oriented system:

    1. All data is private. Period. (This rule applies to all 
implementation details, not just the data.)
    2. get and set functions are evil. (They're just elaborate ways to 
make the data public.)
    3. Never ask an object for the information you need to do something; 
rather, ask the object that has the information to do the work for you.
    4. It must be possible to make any change to the way an object is 
implemented, no matter how significant that change may be, by modifying 
the single class that defines that object.
    5. All objects must provide their own UI.

If the system doesn't follow these rules, it isn't object-oriented. It's 
that simple. That's not to say non-object-oriented systems are bad; 
there are many perfectly good procedural systems in the world. 
Nonetheless, not exposing data is a fundamental principle of 
object-oriented systems. If you violate your principles, you're nothing, 
and the same goes for object-oriented systems. If a system violates 
object-oriented principles, it isn't object-oriented; it's some sort of 
weird hybrid that you may or may not ever get to work right.


So, does this suggest that if I want to render, say, an Account object 
in a Web page, I should do something like this:

<%= account.render( xhtml_form_builder ) %>

where xhtml_form_builder is some object that an Account instance knows 
how to manipulate without needing to know the specifics of the rendering 


More information about the Nitro-general mailing list