[jdom-interest] Re: TODO clone [eg]

Dennis Sosnoski dms at sosnoski.com
Sat Apr 14 14:21:43 PDT 2001

Joseph Bowbeer wrote:

> Dennis Sosnoski writes:
> > Why force everyone to check the exception just in case someone
> > at some point wants to implement a non-cloneable subclass?
> My question is: Why implement Cloneable at all?  (Just checking...)

Clone seems useful for working with nodes in a document, where you may often
want to create a duplicate of an existing node.

> > I'd suggest the onus is on the developer implementing
> > a non-clonable subclass to make sure it's not used by
> > anything that expects to clone it
> How can the developer exercise any control over what the user does?

The user is not the one constructing applications out of these hypothetical
uncloneable subclasses, the developer is. Unless your concern is over at some
point expanding the JDOM library itself to include nonclonable subclasses of the
base types - do you see any reason that might be necessary/desirable?

> The Liskov Substitution Principle (LSP) says that a subclass should work
> anywhere a superclass does.  Unless the superclass declares the exception,
> every subclass will be required to be cloneable -- or be in violation of
> LSP.

I don't think you can make this apply for libraries. It certainly doesn't work
for many of the Java libraries (including the Collections classes, which heavily
use UnsupportedOperationException; not that I'm saying this is a good thing...

But I agree that this has been beaten to death, and I'll shut up now.

  - Dennis

More information about the jdom-interest mailing list