Each element in the MVC pattern communicates with each other in very specific ways. Communication is necessitated by a sequence of events that are generally triggered by a user interacting with the application. The sequence of events is represented as follows:
User interacts with a user interface element (e.g. clicks on a button in a view).
The view sends the click event to the controller to decide how to handle it.
The controller changes the model based on how it decides to handle the button click.
The model informs the view that the state of the model has now changed.
The view reads state information from the model and updates itself.
Figure 12-1 shows the graphical representation of the channels of communication between MVC elements. The arrows' directions show the direction of communication.
Figure 12-1. Direction of communication between MVC elements
This is a very simple model of how MVC elements communicate. In some cases the controller can directly tell the view to make changes as well. This is the case only when the changes in the view necessitated by user action don't require a change in the model itself, but simply a change in visuals. For example, think about the process whereby a user selects a song to play in our portable digital music player. The user selects songs from a list using buttons that scroll the list. The view would tell the ...