jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Am I understanding observers/observables correctly? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Am I understanding observers/observables correctly?" Watch "Am I understanding observers/observables correctly?" New topic
Author

Am I understanding observers/observables correctly?

Jon Swanson
Ranch Hand

Joined: Oct 10, 2011
Posts: 200
Here is my effort to implement a GUI that gets information from two panels and displays the information back to one of those panels and another output only panel. It's a lot simpler than what I need to implement eventually, but do I have the idea right? It seemed a little squirrelly to me to be both adding an object as an observer so that its view could be updated and passing the observer in as an argument so that I could access the data.

I'm also a little unsure about my setValue methods in the Observable. Different objects will set different subsets of the data. I 'cheated' in the example since the parameter types were different. Should I define some additional classes for the subsets of my data, which would allow me to more cleanly overload the setValue method? And then define yet another class that contains all this subsets that the notifyObservers() method returns or is it better not to pass an object with the updated data and have a bunch of methods that let each observer pull out what matters to them? And is there a simple way to indicate some subset of the data did not change, so some objects don't need to update?









 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Am I understanding observers/observables correctly?