On 2011/06/09 21:20:52, jhumphries wrote:
But with this, startOption() (for example) jumps on a tangent,
building
something else -- with no way to return to building the original
element.
In a previous API I liked, we actually constructed HTML entirely
vertically using methods that returned void, like this:
HtmlWriter out = new HtmlWriter();
out.startTag("div", "class=", "description");
out.startTag("p");
out.text("Some text");
out.endTag("p");
out.endTag("div");
This works very well in an IDE with "extract method" and other
refactorings. Very long chains of methods tend to get in the way of
that.
However, we didn't define methods at the attribute level. We just had
some overloaded versions of startTag, and checked everything at runtime:
void startTag(String tag);
void startTag(String tag, String att1, String val1);
void startTag(String tag, String att1, String val1, String att2, String
val2);
In an API that has a method call per attribute, I think we need some
method chaining, but we don't necessarily have to put everything into a
single expression.
http://gwt-code-reviews.appspot.com/1455802/
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors