• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Observable/Observer  RSS feed

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The interface java.util.Observer has a method


This is called when a state change occurs in the Observable.
I came across this
Sun Tutorial, but am still unclear as to how do you pass the entire state information using just one Object variable.

Has anyone come across a similar situation...?

Thanks
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object is the ultimate superclass of all other classes; therefore you can pass anything at all: a String describing the change, a special class you've defined for this purpose, an array of Lists of Maps full of interesting data... anything.
 
V Bose
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Object is the ultimate superclass of all other classes; therefore you can pass anything at all: a String describing the change, a special class you've defined for this purpose, an array of Lists of Maps full of interesting data... anything.


You are right. I was thinking about implementation specific issues, such as if one were to pass a List of states that changed, then the Observer would have to parse the list and figure out what changed etc...a little more expensive than I had thought initially...

Thanks
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by V Bose:


You are right. I was thinking about implementation specific issues, such as if one were to pass a List of states that changed, then the Observer would have to parse the list and figure out what changed etc...a little more expensive than I had thought initially...

Thanks


Which is a good reason to create your own implementation of Observer to suit your needs. You don't have to use java.util.Observer or java.util.Observable to do so.
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note the other form of this method that leaves the arbitrary object off. Then I think we'd expect the observer to call the observable and ask what changed or just get all the latest state.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!