> If a method in a superclass changes the value of a property and a
> subclass needs to do something upon the change, do I have to override
> the superclass' method, do something, and then call the superclass'
> method, or should I register a PropertyChangeListener?
Hi,
Either method works, technically. I would think that if you're trying to
listen for a property change, a PropertyChangeListener is the way to go
(it just seems to me that's the whole purpose of the system, so why not
use it?)
Subclassing just to get notification when one property is changed could
get messy I would think, especially if two people both decide to do it,
then one has to subclass the other's code if both want to be notified,
and so on.
Chris
Raymond DeCampo - 18 Jun 2005 19:57 GMT
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 14 lines]
> then one has to subclass the other's code if both want to be notified,
> and so on.
But if I read the OP correctly, he already has a subclass. So
essentially the subclass wants to know when the object's own attributes
are changed. Using a listener system seems kind of overkill for that.
Ray

Signature
XML is the programmer's duct tape.
Chris Head - 18 Jun 2005 20:21 GMT
[snip]
> But if I read the OP correctly, he already has a subclass. So
> essentially the subclass wants to know when the object's own attributes
> are changed. Using a listener system seems kind of overkill for that.
>
> Ray
Hi,
I didn't actually notice that the first time (the subclass is already
there); however... I guess it depends. Look at a JFrame after all: you
subclass it, but you still stick listeners in it for WindowEvents. On
the other hand, if it's something more simple like properties changing,
then I agree catching the modifications in an overridden method might be
less work.
Chris