[Biojava-l] Immutable objects and ChangeListeners
Thomas Down
td2@sanger.ac.uk
Mon, 8 Jan 2001 19:49:09 +0000
On Mon, Jan 08, 2001 at 06:47:59PM +0000, Tom Oinn wrote:
>
> > As the methods are not allowed to throw exceptions, how can you
> > politely say "Are you sure you want to listen for changes - this
> > object is immutable" ?
>
> In this case it's likely to be an error in the application code isn't
> it? You can always throw a RuntimeException of some kind in this case.
> It's not very 'polite' but you wouldn't expect it to every appear in a
> finished application, it would only do so if there were errors I would
> have thought.
Error? I really don't see this at all. By calling addChangeListener
on an object, you are just expressing concern that an object
might change in the future, and asking that object to let you
know if changes do occur. If that object knows it isn't going
to change, then it can simply ignore the addChangeListener.
Actually, trying to define mutability is itself a pretty
tricky problem. Sure, some implementations are immutable
per se, but you can also have cases like ReversedSymbolList
which could wrap eith a mutable or an immutable underlying
SymbolList. Should the behaviour of addChangeListener differ
according to the underlying implementation? This is getting
onto nasty territory, and i'm much happier with the
current `no exceptions' interface.
Thomas.
--
``If I was going to carry a large axe on my back to a diplomatic
function I think I'd want it glittery too.''
-- Terry Pratchett