From the controller comments: /* * This code implements the simplest MVC (Model View Controller) I could think of. * * * In MVC: * * The Controller sets up the model and view and starts the program. * * The View displays the current data and/or interacts with the user * to get new data for the Model. * * The Model maintains the data and notifies the View when done with any modifications. * * There are many variations on this theme, but this is a basic approach. * * * The advantange of the MVC is that it is less complex than writing an application * where the view and data are intertwined in a single file. * * So the view gets new data from the user and passes it to the model. * * The Model changes the data based on that input and notifies the View which * then redisplays the data. * * Then (when it is necessary) the View interacts again with the user. * * Normally MVC is reserved for complex GUI programs but an example of that * nature tends to obscure the details. * * This example, which uses console I/O, takes advantage of the * Java MVC class Observable and the interface Observer and does not have a complex GUI. * * Since the model inherits Observable it can make use of the method: notifyObservers(). * The model calls notifyObservers() when the data (state) has changed. * * Since the view is an Observer, it must implement the method: update() * update is called by the model's call to notifyObservers() * * Kenneth L Moore Professor CCAC created: 2.6.2012 * */
Source Code