CMPT 300 Design Patterns
Mayterm 2008
MVC - Mode, View & Controller
The MVC pattern is an example of a compound pattern - it consists of multiple
patterns. The idea behind it is that you seperate the business logic of the
application the from actual data and display methods of that data. The model is the data,
the view is the user-interface for the user (it can be a GUI,
command line, or other type of interface), and the controller
is what manages all the interactions
between the model and the view. An example of an MVC in the Java API is Swing.
In UML:
An Example:
In UML:
The Lab:
Implement the controller and two models. The view is done for you, just
hook in your controller and models in the noted places. The models just process
the input and put the output back in the view. The controller, while simple,
just receives updates from the view and passes them to the models.
The controller should take in two models and setup the view with the models
and the controller and then call createView() on the
view.
The Models will implements the observer pattern. The model is the subject
and the observer is the view. The view calls registerObserver()
in the constructor to the models. So just make sure that the interface is
implemented correctly.