Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Subclassing and check methods

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: "Bradley S. Huffman" <hip AT cs.okstate.edu>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Subclassing and check methods
  • Date: Fri, 12 Mar 2004 10:52:51 -0500

At 9:37 AM -0600 3/12/04, Bradley S. Huffman wrote:

If I subclass Element and override checkInsertChild to check that elements
with local name "foo" can only contain children with local name "bar", what
do I do about setLocalName? Think about the case of replacing nodes in a
document. Obviously I can create a "foo" element by recycling a existing
element and using setLocalName, skipping the checks in checkInsertChild
completely.

That's a good one! Devious thinking. I like it. :-)

You're right. That would be a problem with the current checkFoo startegy. However, I think the proposed strategy (make all mutator methods non-final) would plus the hole since the subclass that wishes to enforce the rules could override insertChild and setLocalName. Because the constraints would have to be verified across several classes, to really enforce it, a parent would have to never allow an object from outside its known friends to be added to itself, but I think that would be possible.
--

Elliotte Rusty Harold
elharo AT metalab.unc.edu
Effective XML (Addison-Wesley, 2003)
http://www.cafeconleche.org/books/effectivexml
http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA




Archive powered by MHonArc 2.6.24.

Top of Page