File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

model class

 
Bobby Jones
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to do this and I have no clue...
I have to design, implement, and document three observers and one model. The model class stores and maintains a one-dimensional set
of data. The three observer classes display the data in different forms such as a one-column spreadsheet, a pie chart, a bar
chart, or text output. I need to use the Java graphics library to implement all of these observers as a part of one Java stand-alone application. At least one of the observers should be used to input data. The other two observers may be restricted to output only.
Thanks
 
Grant Crofton
Ranch Hand
Posts: 154
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it you're confused about? The whole oberver-observable thing or implementing the graphical observers?
If you need to find out about observable stuff you'd probably be best of checking out a book on design patterns - it's also called 'publish-subscribe'.
Here's what I remenber: Basically, there is a class which holds data, and one or more other classes that observe it.
When the observed class's data gets changed, it tells all the observers this, and sends them the new data.
normally the observed class would have an array (or similar) of pointers to 'observers'. To be notified about changes (to observe the class), an observing class would have to 'register' itself with the observed class (the observed class would need some method to register observers).
Then, whenever the observed class's data changed, it woulld go through it's registered observers and let them know. It may send it's new data at the same time, or (as is ususally the case) it might be down to the observer to get the data.
To implement this in Java, you might want to check out the Observable class and the Observer interface.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic