[jdom-interest] Query regarding the Parent/Child interfaces.

Simon Gauld Simon.Gauld at three.co.uk
Wed Mar 17 04:06:07 PST 2004


It's been a long, long time since I looked at the lists, so excuse me if I'm
bringing up a dead topic however it seems relevant as #1 is about to be
released.  Bear with me - controversial questions are ahead!:

Regarding the Parent/Child interfaces on the Element class -

- I have always understood that the use of interfaces within Java is to
describe  relationships between objects in terms of Object A "is a" B.  For
example, "a Pineapple is a Fruit".   

(Please excuse my OO 101) - 

this allows me as a programmer to express common functionality across
objects. 

Assuming I didn't misunderstand that part of my OO class, then this means
that when combined with java's nice instanceof, I can now determine if a
Pinnable "Is A" fruit, by saying  

if ( pineapple instanceof Fruit ) {
	.. and do pineapple related menu stuff


-- applying this to the JDOM world now, I can say

if ( myElt instaneof Parent ) {
   // 
	parentCount++;

(Okay, OO 101 is finished.)

-- except, this isn't a correct way of determining if a given Element is
actually a Parent ("Parent" in my world means it has children, not it can
have children.  For example, a loose model of myself might be

class simon implements person;		// note not class simon implements
parent, child, person.  

because I ain't a parent.  I work out if I'm a parent by being asked -
"simon, do you have any children?" - at which point I say "No".  At some
point I might say "Yes" in the future, meaning I am a parent.

Elements now look to me like parents , *always*.  If they have children, if
they don't, they're parents.   Similarly the whole shebang applies to the
Child interface - a new Element instance not attached to anything "is a
Parent" and "is a Child".  It isn't, is it?.

Now I know that I can ask an Element if it is a parent by asking for a count
of its children, however the model seems to be wrong.  When and why did the
model change to have Parent and Child interfaces on the Element.   Was it
because asking .getChildren().size() > 0 was deemed not enough?

.s


simon gauld
programmer, enabling services, 3
direct 01628 76 5443
mobile 07711 314 053
video  07782 246 649 
www.three.co.uk


________________________________________________________________________

This e-mail message (including any attachment) is intended only for the personal 
use of the recipient(s) named above. This message is confidential and may be 
legally privileged.  If you are not an intended recipient, you may not review, copy or 
distribute this message. If you have received this communication in error, please notify 
us immediately by e-mail and delete the original message.

Any views or opinions expressed in this message are those of the author only. 
Furthermore, this message (including any attachment) does not create any legally 
binding rights or obligations whatsoever, which may only be created by the exchange 
of hard copy documents signed by a duly authorised representative of Hutchison 
3G UK Limited.
________________________________________________________________________




More information about the jdom-interest mailing list