Instantiating the Model-View-Controller Architecture

The Model-View-Controller pattern is a popular architecture for desk top applications.

The Model-View-Controller pattern is often refined by the Publisher-Subscriber pattern:

This solves the View Notification Problem: Without a reference from Model to View, how will views know when the model has been updated and that they should refresh themselves?

The Framework Design

(See Building a GUI in Java for a simple example of incorporating the MVC pattern into Swing.)

We can formalize the Model-View-Controller architecture with a Java framework:

Notes

In Java Observer = Subscriber and Observable = Publisher

The Model contains application data and so must be persistent (i.e., savable). For this reason Model implements the Serializable interface.

The View (i.e., the GUI) observes the model. It also maintains the single reference to the model.

The controller base class implements the ActionListener interface so that instances of subclasses can register themselves with GUI controls.

The Implementation

Model

Model.java

View

View.java

GUIUtils.java

Controller

Controller.java

FileController

FileController.java

An instanatiation of the mvc framework

Maze Challenge