• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Am I understanding observers/observables correctly?

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?









reply
    Bookmark Topic Watch Topic
  • New Topic