[jdom-interest] Toward beta 9
Elliotte Rusty Harold
elharo at metalab.unc.edu
Wed Apr 9 11:33:23 PDT 2003
At 12:18 PM -0600 4/9/03, Alex Rosen wrote:
>This is simply not true. If JDOM were a parser then that would be true,
>but JDOM is not a parser. Section 1 of the XML spec makes it clear that
>the requirements that it lays out are for parsers only. When you're
>creating and writing XML, you can choose whether to be strict or
>lenient, and for good reason - different people will have different
>requirements.
It's not a rule of XML. It's a rule of good object oriented design.
If you're designing a classes that represents a time of day, you
don't let the hours field be set to 25. We're modelling XML so we
need to faithfully model XML. An illegal name or character in a node
is as wrong as a Clock that strikes 25. It is as wrong as a sockets
API that allows programmers to use five byte IP addresses.
Classes have invariants. Methods have preconditions and post
conditions. These are essential components of OOP, even in languages
like Java that don't expose them as explicit, first-order constructs.
This is far and away the most important reason to even have data
encapsulation, though regrettably it is the one least frequently
taught. Separation of interface from implementation, the most
frequently cited reason for data encapsulation and access protection,
is at best the third most important reason, and a distant third at
that. (The second most important reason is simplicity, which
invariants also contribute too.)
One big reason a typical programmer uses an API written by experts
instead of doing everything themselves is so they don't have to be
experts, so they don't have to know every last rule about what is and
is not legal. If client programmers are going to take responsibility
for maintaining the constraints themselves, they might as well use
strings and streams. That would be even faster and more memory
efficient.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| Processing XML with Java (Addison-Wesley, 2002) |
| http://www.cafeconleche.org/books/xmljava |
| http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+
More information about the jdom-interest
mailing list