Skip to Main Content
Java and XML, Second Edition
book

Java and XML, Second Edition

by Brett McLaughlin
August 2001
Intermediate to advanced content levelIntermediate to advanced
528 pages
14h 35m
English
O'Reilly Media, Inc.
Content preview from Java and XML, Second Edition

Gotcha!

As with the other chapters on APIs, I will address a few more tricky items that relate to the topics in this chapter. These are common problems that can cause you to beat your head against the wall, so try and avoid them.

More on Subclassing

Since I talked about factories and custom classes in this chapter, it’s worth pointing out a few important things about subclassing that can be gotcha items. When you extend a class, and in particular the JDOM classes, you need to ensure that your custom behavior is going to be activated as you want it to. In other words, ensure that there is no path from an application through your subclass and to the superclass that isn’t a path you are willing to live with. In almost every case, this involves ensuring that you override each constructor of the superclass. You’ll notice that in Example 8-1, the ORAElement class, I overrode all four of the Element class’s constructors. This ensured that any application using ORAElement would have to create the object with one of these constructors. While that might seem like a trivial detail, imagine if I had left out the constructor that took in a name and URI for the element. This step effectively reduces the number of ways to construct the object by one. That might seem trivial, but it’s not!

Continuing with this hypothetical, you implement a CustomJDOMFactory class, like the one shown in Example 8-2, and override the various element( ) methods. However, you would probably forget to override element(String ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java and XML, 3rd Edition

Java and XML, 3rd Edition

Brett McLaughlin, Justin Edelson
Java & XML Data Binding

Java & XML Data Binding

Brett McLaughlin

Publisher Resources

ISBN: 0596001975Supplemental ContentCatalog PageErrata