aspose file tools*
The moose likes Beginning Java and the fly likes model class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "model class" Watch "model class" New topic
Author

model class

Bobby Jones
Greenhorn

Joined: Feb 12, 2001
Posts: 2
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

Joined: Nov 08, 2000
Posts: 154
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.
 
Consider Paul's rocket mass heater.
 
subject: model class