Observable/Observer

S

Srikanth

Is there any difference in performance if we use ordinary call back
methods on indivisual objects separately instead of Observable/Observer
api.
I have an Observable class which has a single Observer, when there is
only one Observer is it worth using Observable/Observer api or is it
better to use a call nack method instead. Off course the design looks
better. But other than that is there any other difference?
 
C

Chris Smith

Srikanth said:
Is there any difference in performance if we use ordinary call back
methods on indivisual objects separately instead of Observable/Observer
api.
I have an Observable class which has a single Observer, when there is
only one Observer is it worth using Observable/Observer api or is it
better to use a call nack method instead. Off course the design looks
better. But other than that is there any other difference?

There shouldn't be a significant difference in performance that I can
see.

By and large, though, use of Observable/Observer is very rare. Because
it requires that you subclass the Observable class, it's not very clean,
easy to retro-fit into existing code, nor easy to refactor after it's
done. For the most part, modern projects use the event listener idiom
instead, by declaring their own interfaces with callback methods. See
Swing for plenty of examples.

Requiring a single listener is actually considered proper for the event
listener idiom, so you're in luck... if you are still worried about
keeping a list of listeners, you don't have to. Just call your method
setXXXListener instead of addXXXListener.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top