Setting up an MVC Model
Steps for implementing MVC: Want to set up a communication framework among
the model, view, and controller
- Design a listener interface for views (observers): The model uses the
listener interface to notify the views of changes to the model.
- Implement model with methods for controller to change model and for the
view to access model info
- implement query methods so views can access state information
- implement registration/de-registration methods for views
- implement change methods for the controller. These methods will
change the model's state
- implement notification methods for the views. Specifically,
for each method M in the listener interface, implement a notifyM() method
in the model that notifies listeners that the model's state has
changed and provides the old value(s) for changed variables. The
view can query for the new values.
- View implementation
- register the view with the model at view creation time (typically
in the constructor)
- have view implement listener interface and repaint affected
screen regions
- if the view consists entirely of pre-defined widgets, the widgets
will automatically redraw themselves
- Controller implementation: translate events into change method calls
on the model
- typically bundled with the view, because each view is so
idiosyncratic that it's tough to write independent controllers