• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Using Observable/Observer

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic