CMSC 498B: Developing User Interfaces - Spring 2002

Model-View-Controller (MVC)

Model View Controller (MVC)

 

Model

Information
Actions

View

Map information to visual displays

Controller

Map events to modifications of model
Map events to modifications of view

Why bother?

  • Extensibility (e.g., swap in new views)
  • Maintainability (e.g., modify controller without modifying other parts)
  • Generality (e.g., multiple simultaneous views)

Scroll bar example

Model

Information

Current value, Extent, Max, Min, Step size, Page size

Actions

Set/get value, extent, Stepup/stepdown, Pageup/pagedown

View

Position of the thumb given max, min and value, and extent

Controller

Input events

MouseDown
MouseMove
MouseUp

How to translate into actions

Geometry questions

View update questions

Keyboard events

How does the view know when the model has changed?

=> Model generates Change event.  View listens to that event, and requests a rerender of itself - using the model when it is time to render.

All actions are triggered from the controller.

Calculator example

Model

Information

Current value  (Generates ValueChanged event)
Accumulator value
Saved operator

Actions

Enter number
Perform operation

View

Static parts (redisplay on interaction events)

Number part  (redisplay on value changed event)

Controller

Input onto buttons

Essential geometry

Spreadsheet

Model

How many views?

Look at upper view when cell is modified

Type a formula

Type a dependent formula

Controller

 

Is it clear why we worry about graphics and making our own widgets yet?