Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] RFE: Element.appendChild(String text) should return "this" for chaining

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] RFE: Element.appendChild(String text) should return "this" for chaining
  • Date: Mon, 16 Aug 2004 11:09:02 -0700

RFE: Element.appendChild(String text) should return "this" for chaining.

Knowing that some people feel strongly against chaining I'm not promoting using chaining everywhere and inappropriately, but there is one place where it would be very practical, as it arises very frequently: Consider adding a couple of items with Text values to a list of items, as follows.

Element items = new Element("items");
Element item = new Element("item");
item.appendChild("car");
items.appendChild(item);
item = new Element("item");
item.appendChild("boat");
items.appendChild(item);
item = new Element("item");
item.appendChild("plane");
items.appendChild(item);

Do you immediately see what the code is about? Probably not.
If Element.appendChild(String text) would return this one could write this more understandably and consisely as follows.

Element items = new Element("items");
items.appendChild(new
Element("item").appendChild("car"));
items.appendChild(new
Element("item").appendChild("boat"));
items.appendChild(new
Element("item").appendChild("plane"));

The case occurs sufficiently often to consider it, IMHO.
Plus the change would be backwards compatible since the method currently returns void.

Wolfgang.





Archive powered by MHonArc 2.6.24.

Top of Page