[jdom-interest] Element.toString() being final
Alex Chaffee
guru at edamame.stinky.com
Wed Jul 5 00:27:39 PDT 2000
This is one of the problems I have with Swing: the value of
"toString()" should NEVER be shown to a user in a non-debugging
context. They mixed code and UI by poviding that short-sighted
shortcut to making a true view. My advice: if you're not going to go
through the effort of making a custom view (which isn't actually that
hard), then at least make the data objects be wrappers, as in:
public class ElementView {
public Element element;
public ElementView(Element e) { this.element = e; }
public String toString() {
return "My personal transform of element:" + element.getContent() + "...";
}
}
Inheritance is, imho, vastly overrated compared to delegation.
- Alex
P.S. I think toString() should probably be non-final as well. :-)
On Wed, Jun 28, 2000 at 12:16:57PM +0200, Arvidsson, Hokan wrote:
> Hi all,
>
> The method 'toString()' of class 'Element' is declared as 'final'.
> This causes problem when you use jdom in connection with the Swing JTree
> class.
> When swing displays a tree node, it calls Object.toString(). Then return
> value of Element.toString() is not always suited.
> It would be nice to be able to overwrite Element.toString() in a sub class
> to Element.
> This way you may display your jdom trees very nicely.
>
>
> Thanks,
> Håkan
>
> Håkan Arvidsson
> Consultant
> Software AG Switzerland
> Tel. ..41-1-745 91 11
>
--
Alex Chaffee mailto:alex at jguru.com
jGuru - Java News and FAQs http://www.jguru.com/alex/
Creator of Gamelan http://www.gamelan.com/
Founder of Purple Technology http://www.purpletech.com/
Curator of Stinky Art Collective http://www.stinky.com/
More information about the jdom-interest
mailing list