Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

To listen or to override

Thread view: 
- - 18 Jun 2005 07:38 GMT
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?
Chris Head - 18 Jun 2005 16:47 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.