MVC Paper
MVC Paper
MVC Paper
Trygve Reenskaug
Dept. of Informatics
University of Oslo
I made the first implementation and wrote the original MVC reports while I
was a visiting scientist at Xerox Palo Alto Research Laboratory (PARC) in
1978/79. MVC was created as an obvious solution to the general problem of
giving users control over their information as seen from multiple perspectives.
MVC has created a surprising amount of interest. Some texts even use
perverted variants for the opposite purpose of making the computer control the
user.
MVC was conceived as a general solution to the problem of users controlling a
large and complex data set. The hardest part was to hit upon good names for
the different architectural components. Model-View-Editor was the first set.
They are described in my first note of May 12, 1979: THING-MODEL-VIEW-
EDITOR -.an Example from a planningsystem. A scanned version is included
below.
After long discussions, particularly with Adele Goldberg, I ended with the
terms Model-View-Controller as described in my second note of December 10,
1979: MODELS - VIEWS – CONTROLLERS. A scanned version is included at
the end of this document.
Jim Althoff and others implemented a version of MVC for the Smalltalk-80
class library after I had left Xerox PARC; I was in not involved in this work.
Oslo, February 12, 2007
Trygve Reenskaug
THING-MODEL-VIEW-EDITOR
an Example from a planningsystem
To LRG
From Trygve Reenskaug
Filed on [IVY]<Reenskaug>SMALL> TERMIN0LOGY2.DOC
Date 12 MAY 1979
THING
DESCRIPTION OF TERM
Something that is of interest to the user. It could be concrete, like a house or an integrated
circuit. It could be abstract, like a new idea or opinions about a paper. It could be a whole,
like a computer, or a part, like a circuit element.
MODEL
DEFINITION
A Model is an active representation of an abstraction in the form of data in a computing
system
COMMENTS
As mentioned above, there are in general many different ways of abstracting the same Thing,
and it is therefore often useful with several, coexisting Models of a given 'Thing.
Alternatively, one may think of the project as having one, large Model that is subdivided into
a number of sub-Models.
The models are represented in the computer as a
collection of data together with the methods
necessary to process these data.
Ideally, all models should be totally consistent. This
ideal is not attainable in practice because it would
require an overwhelming bureaucracy and stifling
rigidity. One should therefore accept some
inconsistencies, the aim being that the total set of
models should be a reasonabely accurate
representation of the project without spending too
much effort on trivialities.
In our example, a given network Model is
represented in the Smalltalk system as an instance of class NetworkModel. Each activity in
the network Model is represented as an instance of class Activity.
One of the fields defined for class NetworkModel is activities, a Dictionary connecting
activity names (a UniqueString) and instances of Activity. Three of the fields defined for class
Activity are network, predecessors and successors. network contains a pointer to the
relevant instance of NetworkModel, and predecessors and successors are Vectors of pointers
to instances of Activity.
Within this general framework, we may now add information about our project that may be
connected to the network as a whole, and to each of its activities. To the network, we may for
example add the fields plannedStart and plannedFinish. To the definition of class Activity
we may add the fields duration, earlyStart, lateStart, and resourccRcquirements. We may
also add fields for late start and late finish, but decide to compute these quantities whenever
needed. (From duration and earlyStart or lateStart).
Note that the network Model with its sub-Models for each activity contains no information
about how the information may be shown on the screen, it is a clean representation of the
abstract project model.
VIEW
DEFINITION
To any given Model there is attached one or more Views, each View being capable of
showing one or more pictorial representations of the Model on the screen and on hardcopy. A
View is also able to perform such operations upon the Model that is reasonabely associated
with that View.
COMMENT
The implementation of all Views would be simplified if they were based upon the Form-Path-
Image metaphors.
The diagram above is an instance of class DiagramView. It is the only example where the data
in the View cannot be fully deduced from its Model, and it must have fields containing the
shape and position of all the symbols, since this information is not part of the Model itself.
(Programs exist for the automatic positioning of symbols within a diagram. but we assume that at least some
manual editing will be required). The placement of the arrows may be deduced from the
dependencies between the activitities, this information may be fetched from the
NetworkModel whenever needed for the display. Such a procedure will be very slow,
however, and we assume that the Diagram View keeps a copy of that information for
efficiency reasons.
Just as all the other views, a Diagram View will need to supply the two operations needed to
select an activity, and the operations needed for scrolling (this time in two dimensions). In
addition, it will need some operations on the View itself, they have to do with the positioning
of the symbols in the diagram. Other operations have to do with network Model, for example
modify dependencies of an activity and transfer activity from one network to another.
This View provides an alternative to the previous example. The symbols are smaller, and it
therefore possible to present a larger part of the network on the screen. The small symbol size
makes it impractical to print the activity name in the symbol, and the user must get this
information by some other means.
The network diagram is presented on a gridded background. This is used when the user is
laying out the diagram, and the dots define the permissible positions of the activity symbols.
This View could be implemented as a subclass of DiagramView, or both could be subclasses
of some common View. In the present implementation, however, both Views may be
generated alternately by the same object: class Diagram View has has a field displayType that
may take the values #large or #small, and the various display methods are controlled by that
field. The gridding is displayed in the diagram through a separate method.
This View shows the activities along the vertical axis and time along the horizontal axis. In
this particular view, only one time schedule for each activity is shown. Through varying the
shading, it is quite easy to extend the presentation to include how much each activity may
float in time without upsetting the overall project schedule.
The diagram is an instance of class GanttView, which is a subclass of ChartView. ChartView
knows about the diagram background: axis with legend, gridding etc. It does not know
anything about the information to be put into the diagram, in this case the horizontal bars. It
aids its subclasses in presenting this information, however, through providing methods for
conversion from whatever coordinate system is used externally to the frame coordinates of the
diagram.
Class GanttView understands a number of messages from the user, most commonly given
through an Editor. One such message is viewNetwork:, this message provides the name of
the current NetworkModel. It will also be able to answer a question about which activity
belongs to the bar under a given point in the diagram, and to select the bar belonging to a
given activity. It is also able to pass on operations on the network and its activities that are
related to this particular View. Typical operations have to do with modifying the current
schedule. Operations should be provided for planning the network as a whole (backload: and
frontload:), for modifying the schedule of a single activity (plannedStart: and
planncdFinish:), and for letting the consequences of such a modification work its way
towards the front or back end of the network.
The NetworkModel must be able to answer a few questions rom a GanttPane giving a list of
all activities, the schedule of the network as a whole, and the schedule of each individual
activity.
This diagram shows the sum of the resource requirements for the activities as a function of
time. (In general, there will be one such diagram for each resource type.)
The diagram is an instance of class ResourceView, which is another subclass of
DiagramView. The comments about the Gantt-diagram apply to this one as well, but the
concept of selection needs elaboration. The views answer to who:point? could be the set of all
activities that need resources at the time cooresponding to the point's x-value. The reaction to
the message select: activity could be to highlight the resource requirements of that particular
activity. For symmetry, it would be nice to combine the two, and open the possibility for
multiple selections in all NetworkModel Views.
EDITOR
DEFINITION
An Editor is an interface between a user and one or more views. It provides the user with a
suitable command system, for example in the form of menus that may change dynamically
according to the current context. It provides the Views with the necessary coordination and
command messages.
COMMENT
A user task may commonly be better performed with several Views present on the screen at
the same time. The user will want to manipulate these Views through pointing at them,
through selection in menus, or through some other means. Commands like selection typically
apply to several Views at the same time. The purpose of an Editor is to establish and position
a given set of Views on the screen, to coordinate them and to provide the user with a suitable
command interface.
MODELS
Models represent knowledge. A model could be a single object (rather uninteresting), or it
could be some structure of objects. The proposed implementation supports knowledge
represented in something resembling semantic nets (If I understand Laura correctly)
There should be a one-to-one correspondence between the model and its parts on the one
hand, and the represented world as perceived by the owner of the model on the other hand.
The nodes of a model should therefore represent an identifiable part of the problem.
The nodes of a model should all be on the same problem level, it is confusing and considered
bad form to mix problem-oriented nodes (e.g. calendar appointments) with implementation
details (e.g. paragraphs).
VIEWS
A view is a (visual) representation of its model. It would ordinarily highlight certain attributes
of the model and suppress others. It is thus acting as a presentation filter.
A view is attached to its model (or model part) and gets the data necessary for the presentation
from the model by asking questions. It may also update the model by sending appropriate
messages. All these questions and messages have to be in the terminology of the model, the
view will therefore have to know the semantics of the attributes of the model it represents. (It
may, for example, ask for the model's identifier and expect an instance of Text, it may not
assume that the model is of class Text.)
CONTROLLERS
A controller is the link between a user and the system. It provides the user with input by
arranging for relevant views to present themselves in appropriate places on the screen. It
provides means for user output by presenting the user with menus or other means of giving
commands and data. The controller receives such user output, translates it into the appropriate
messages and pass these messages on .to one or more of the views.
A controller should never supplement the views, it should for example never connect the
views of nodes by drawing arrows between them.
Conversely, a view should never know about user input, such as mouse operations and
keystrokes. It should always be possible to write a method in a controller that sends messages
to views which exactly reproduce any sequence of user commands.