Jump to content

What are Observers in Java


skaterdav85
 Share

Recommended Posts

I was trying to understand the example but i dont see what the difference between an observer and a listener is. Maybe you can compare it to JS even though I know these terms don't apply. In JS, it seems like a 'listener' would be adding an event handler to some html object, so these would be comparable:

JSonClick="someFunction();"JavaaddWindowListener(new LocalWindowListener());

What would the 'observer' be?

Link to comment
Share on other sites

JS's object-oriented model isn't that great, so there is no real comparison. Basically, an observer watches another object for something to happen (doesn't have to be user-driven), and then gets notified when that thing happens. They are a bit like "listeners" in JS - but can you think of what that would be in Java?

Link to comment
Share on other sites

  • 2 months later...

Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.http://www.globalguideline.com/interview_q...ava_Programming

Edited by Chathu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...