|
|
|||
A model class, or usually a set of related classes, encapsulates the purely algorithmic behavior of the application. It presents a well-defined API to other parts of an application. Some of the key relationships are as follows:
The application's document class constructs and owns the model.
The App UI contains a pointer/reference to the model.
An App UI, or an associated class to which it delegates responsibility, receives user commands that the view has passed on and calls model functions appropriately in response to user commands.
Views also contain a pointer/reference to the model. The views calls model functions appropriately in response to user commands. They can also decide to pass the commands to the App UI.
Code this is used to draw the screen in a view reads data from the model, but usually does not modify it. Input events handled by a view do, however, cause changes in the model. A straightforward approach is to allow the view to call the model directly. For more complex applications, you may want to provide a separate class that encapsulates handling input events.