Java Model-View-Controller (MVC)

Remark :

Model-View-Controller (MVC) Structure

Main program

The main program initializes everything and ties everything together.

View

This View doesn’t know about the Controller, except that it provides methods for registering a Controller’s listeners. Other organizations are possible (eg, the Controller’s listeners are non-private variables that can be referenced by the View, the View calls the Controller to get listeners, the View calls methods in the Controller to process actions)

The Controller

The controller process the user requests. It is implemented here as an Observer pattern — the Controller registers listeners that are called when the View detects a user interaction. Based on the user request, the Controller calls methods in the View and Model to accomplish the requested action.

Model

The model is independent of the user interface. It doesn’t know if it’s being used from a text-based, graphical, or web interface. This is the same model used in the presentation example.

Source run