I am trying to get a better understanding of the MVC structure while using Observable and Observer and I am trying to do so by implementing a program that compares files. I want my view to show a list of files and some statistical data. How do I update the view with different data?
For instance, if the statistics change, I want to send the Statistics object to the view so it can update it’s display. But at the same time, if the list of files changes, I want to send the ArrayList to the view so it can update it’s display. Do I use the same update method for both? If so, do I then have my view look to see what the instanceof is and display accordingly?
A good example of how MVC can work is in the Swing framework. Every state change fires one kind of Event, and the objects that want to know about those changes implements Listeners (aka. observers).
So, in summary, you should create one interface called StatisticsListener, like this:
With the event StatisticsEvent:
… and in your class that handles Statistics, you fire the events:
Something like this 😉