[antlr-interest] StringTemplate/MVC design issue
nward at resqsoft.com
Sun Dec 30 18:42:47 PST 2007
Thanks! That helps. I'm not sure I quite picture yet where exactly I add the
factory, but it gives me some new ideas that will help me figure that out.
From: Harald M. Müller [mailto:harald_m_mueller at gmx.de]
Sent: Sunday, December 30, 2007 2:14 PM
To: 'Nathan Ward'; antlr-interest at antlr.org
Subject: RE: [antlr-interest] StringTemplate/MVC design issue
> What we've done so far, is to provide additional methods on our model
> objects. For example, PackageDefinition class has a
> toClassName() and a
> toVariableName() method that simply handles the first letter
> The visitor calls these methods to set attributes on templates. But, I
> think this is the wrong way to do it. With this approach, the model
> knows too much about the view. If we convert to something other than
> Java in the future, the uppercase/lowercase first letter, not to
> mention the other naming conventions may not be necessary and/or may
> be different.
We do currently exactly the same (in a quite large code generator emitting
Java and NHibernate hbm.xmls).
I wouldn't change anything in the machinery behind the scenes, but rather do
about the following:
- Let the model not return strings, but an object of some type
"AbstractName"; the concrete object will be returned by a factory, e.g.
"JavaName" or "CSharpName" or "SQLName". These classes (which do not conform
to an interface!)then habe methods that implement the various idioms on how
to convert a generic "package definition's name" to a Java/C#/... class
name, a variable name, a parameter name etc. If you emit code in some other
language, you would have to have other
- Whatever part of the program selects the templates to be used will also
install the factory.
Whether you then count these classes to be part of the "model" or "view" is
up to you - I would think they are an "intelligent strategy of the view
injected into the model."
(Draw an architecture picture in your documentation where you explain this
P.S. Similar questions often come up in the GUI MVC context: Models often
cannot be THAT abstract w/ regards to the view - showing a list in a listbox
or as a list of radiobuttons requires, although the representations in
principle have the same power, often a few small different
methods/behaviors. Some sort of injection/factory can help there also.
More information about the antlr-interest