|
|
Model / View / Controller (MVC) pattern in a multi-device
configuration
The Model / View / Controller (MVC) pattern is a well-known
recipe for writing software that simultaneously provides different
views of the same set of data. This pattern is widely used
by programmers to structure traditional applications that
run on a single device. Hence, it is a natural starting point
for developing applications to be shared among multiple devices.
There are several possibilities to extend the MVC pattern
to a multi-device configuration, depending on where the different
entities reside.
The MVC pattern for GUI libraries background
The problem of how to give a user several different access
paths to the same set of data simultaneously was addressed
by the developers of Graphical User Interface (GUI) libraries
[PPR01]. The Model / View / Controller
(MVC) pattern was introduced in a Smalltalk GUI library and
is a recipe of how to display the same data in several windows
in different views [KrPo88]. The
user can manipulate the data in any window and the other windows
reflect the changes immediately.
|
|
 |
| |
|
|
|
The roles (participants) in the MVC pattern are:
|
|
|
|

Figure 1. Model / View
/ Controller pattern.
|
|
back to top |
| One of the goals of the MVC pattern is to enable the combination
of a single Model with multiple Views and Controllers, as shown
in Figure 2. The MVC pattern ensures that the Views are kept
synchronized as can be seen from the following example. One
of the Controllers recognizes a valid command from the user's
input. The Controller invokes the corresponding method on the
Model. The Model verifies that the operation is compatible with
the current state, executes it and changes the state correspondingly.
The state change triggers an event that the Model multicasts
to each View.

Figure 2. MVC pattern
with multiple Views and Controllers.
|
|
back to top |
To support multiple Views and Controllers, dependencies must
be kept in a minimum. (A is said to depend on B when the code
of A embeds knowledge about B.) This leads to the following
rules (see Figure 3 for allowed dependencies):
- The Model does not have any dependency on Views or Controllers.
- A View depends on its associated Model. It has to know
the structure of the Model's state to render it.
- A View does not have a dependency on Controllers. Therefore
several different Controllers can be associated with the
same View.
- A Controller depends on its associated Model and View.
The Model defines the operations the Controller can invoke
and the View defines the context in which the Controller
interprets the user input. This makes the Controller tightly
coupled to the View.
Figure 3. Allowed dependencies
in the MVC pattern.
|
|
back to top |
Another precondition to support multiple Views and Controllers
is to keep interactions to a minimum. In particular a Controller
must never directly affect the rendering of its associated View.
Instead, user input must make a complete round trip through
the Model before its effects become visible in the View. This
rule guarantees that a state change updates all Views and the
Views remain synchronized. Often implementations with a single
Controller violate this rule because of sloppy thinking: "I
already know that this state change will occur, and therefore
don't need to wait for the Model to tell me about it".
This is wrong for two reasons:
- The Model can veto the operation for some reason. The
operation will not occur.
- Other Controllers concurrently invoke operations on the
Model. Some other operation can slip in between, which fundamentally
changes the rendering and makes any assumptions about it
invalid.
It is impossible to extend such shortcut implementations
with additional Controllers.
|
|
|
| |
|
|
Extending the MVC pattern to multi-device applications
Although the MVC pattern was originally devised for GUIs
running on a single machine, it is relatively straightforward
to extend it in two dimensions. First, it can be extended
to non-GUI interactions such as speech. Second, it can be
extended to a distributed system, where some interfaces between
Model, View and Controller cross the network. The placement
of the Model, View and Controller then becomes crucial.
A server-centric placement puts the Model on a server.
The mobile devices contain View / Controller pairs that interface
to the Model via a network protocol, for example RPC. This
approach has the benefit of relative simplicity. However,
it is not suitable for environments where connectivity is
not continuous, since as soon as there is a connectivity loss,
the Controller and the View cannot interact with the Model.
Figure 5: Server-centric function placement.
|
|
back to top |
|
A device-centric placement puts all three functions
on each device: Model, View and Controller. The Model, which
exists conceptually only in one instance, is replicated among
the devices. A replication protocol keeps the Model replicas
synchronized by propagating state changes in one replica to
the other replicas.

Figure 6: Function placement with replicated
model.
|
|
back to top |
| |
|
|
References
| [KrPo88] |
|
Glenn E. Krasner, Stephen T. Pope, "A
cookbook for using the model-view controller user interface
paradigm in Smalltalk-80", Journal of Object-Oriented
Programming, Vol.1 No. 3, August / September 1988. |
| [PPR01] |
|
Portland
Pattern Repository's Wiki, page "Model View Controller",
accessed August 2001. |
|
|
back to top |
| |
|
|
|
|