W3C home > Mailing lists > Public > www-dom@w3.org > October to December 1999

Re: DOM L2 comments, various

From: John Cowan <cowan@locke.ccil.org>
Date: Tue, 5 Oct 1999 12:41:17 -0400 (EDT)
Message-Id: <199910051641.MAA19845@locke.ccil.org>
To: lehors@w3.org (Arnaud Le Hors)
Cc: www-dom@w3.org
Arnaud Le Hors scripsit:

> John Cowan wrote:
> > 
> > Just because an object implements Attr is no guarantee
> > that it is an attribute.
> 
> Is this because in your implementation the same class is used for
> different types of nodes? I bet it is.

Indeed.

> I used to do the same. Basically
> all the HTML*Element interfaces were implemented on the same class. But
> I finally decided that it was a bug in my implementation to make
> instanceof unreliable. Think about it. If instanceof(Attr) returns true,
> it'd better be an Attr node, or your users will get very confused.

Au contraire.  I believe that using instanceof for type discrimination
(as in, if (x instanceof Element) do_this else if (x instanceof Attr) do_that)
is the worst kind of bogus OOP.  My implementation makes zero
guarantees about underlying classes, how many or with what crossovers.

BTW, I don't see how you can implement all HTML*Element interfaces with
one class in Java, since some of the instance methods have incompatible
return types, and Java doesn't allow overloading on the return type.
I needed IIRC six classes.

-- 
John Cowan                                   cowan@ccil.org
       I am a member of a civilization. --David Brin
Received on Tuesday, 5 October 1999 11:58:45 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:46 GMT