the mvc architecture

12
Jan-24-05 © 2001-2005 by David A. Carr 1 L INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET The MVC Architecture SMD158 Interactive Systems Spring 2003 Jan-24-05 © 2001-2005 by David A. Carr 2 L Overview Architecture’s place Dialog control Model-View-Controller Architecture Swing and MVC Architecture and the Event-Action-State Paradigm Jan-24-05 © 2001-2005 by David A. Carr 3 L INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Architecture’s Place

Upload: others

Post on 01-Mar-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 1 L

INSTITUTIONEN FÖRSYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

The MVC Architecture

SMD158

Interactive Systems

Spring 2003

Jan-24-05 © 2001-2005 by David A. Carr 2 L

Overview

• Architecture’s place

• Dialog control

• Model-View-Controller Architecture

• Swing and MVC

• Architecture and the Event-Action-State Paradigm

Jan-24-05 © 2001-2005 by David A. Carr 3 L

INSTITUTIONEN FÖRSYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Architecture’s Place

Page 2: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 4 L

What is a Software Architecture?

A method by which software systems are decomposed into components and a specification of how these components interact.

The internal organization of software systems.

Jan-24-05 © 2001-2005 by David A. Carr 5 L

Remember - The Software Engineering Life Cycle

• Six phases:- Requirements definition- Specification- Implementation- Testing- Installation- Maintenance

• Software architecture is concerned with:- The specification phase- Internal design

Jan-24-05 © 2001-2005 by David A. Carr 6 L

Remember - An Interactive Systems View of theSoftware

Functional Core (FC) Dialog Control

Interaction Objects Window System

Device Drivers

• IS architecture is mostly about dialog control

Page 3: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 7 L

Software Architecture

• Guides the process of function partition within thesystem

• Specifies the system’s division in to layers

• Specifies the interfaces between layers

• Must consider usability and system issues

Jan-24-05 © 2001-2005 by David A. Carr 8 L

Why is Architecture Important?

• Consider a dialog box for a long operation (e.g.,printing)

• If the need to cancel is discovered late,- How much extra work is it?

- What is it’s impact on the system design?

• You want to avoid: “We can’t do that!”- Decoupling patterns

Jan-24-05 © 2001-2005 by David A. Carr 9 L

Architecture without Cancel

Page 4: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 10 L

Adding the Cancel Capability

Jan-24-05 © 2001-2005 by David A. Carr 11 L

Interactive System Issues

• Usability issues- Multiple representations

- Multi-threading

- Non-preemptive

- Reachable

- Observable

- Predictable

• System issues- Modifiable

- Portable

Jan-24-05 © 2001-2005 by David A. Carr 12 L

INSTITUTIONEN FÖRSYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Dialog Control

Page 5: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 13 L

Dialog Control

• Maps between:- Functional core

- Interaction objects

• Control interface dynamicbehavior

• Support incrementaldevelopment

• Design requirements- Interleaving

- Protocol with the functionalcore

- General services

+ Undo/redo

+ Cut/copy/paste

+ Help

Jan-24-05 © 2001-2005 by David A. Carr 14 L

Design Issues for Interleaving

• Operator-system styles- System driven

+ System in control

+ Good for casual use ofcomplex system (wizards)

- User driven

+ User in control

+ Flexible, but moredemanding

+ Harder to implement

• Among system Components- Where is control, FC, Dialog

Controller (DC), both?+ In FC ⇒ feedback like

rubber banding difficult+ In DC ⇒ semantic

feedback on drag-and-drop difficult

Jan-24-05 © 2001-2005 by David A. Carr 15 L

4 Issues in Dialog/Functional Core Messaging

• Correct level of abstractionfor data transfer

- Separation of FC andpresentation

⇒No presentation media

⇒In FC units

• Ownership of the data- FC, DC, both?

- Synchronization need if both

• Data Definition- Implicit by parameter set

- Explicit by data structure

⇒Easier modification

⇒Allows semanticdelegation

⇒Eases automatic UIgeneration

• Data access- Procedural (API)

- Declarative (Constraints)

Page 6: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 16 L

General Services

• Undo/Redo- History and coordination at all

levels

- Needs stack of reversecommands

• Context sensitive help- Needs system and user

models

- Must monitor system stateand history

- DC controls

• Cut-Copy-Paste- At the semantic (FC) level

- Within or between applications

- Data formats are a complication

+ Clipboard in presentationunits⇒Violates FC level⇒Needs translation

⇒Must operate onpresentation, DC, & FClevels

Jan-24-05 © 2001-2005 by David A. Carr 17 L

INSTITUTIONEN FÖRSYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Model-View-Controller Architecture

Jan-24-05 © 2001-2005 by David A. Carr 18 L

Model-View-Controller

Model

Controller View

Page 7: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 19 L

Model-View-Controller

Model• Notifies all views when changed• Defines connection to controller• Cut, Copy, Paste• Undo, Redo• Help

View• Draw the model• Update the model’s display• Determine which objects are selected.

Controller• Receive and dispatch events + Spatially + Sequentially• Defines dialog

Jan-24-05 © 2001-2005 by David A. Carr 20 L

Advantages of the MVC Model

• Separation of concerns- Controller

+ Handles input and sequencing, i.e., dialog+ Interacts tightly with View for feedback

• Quick response for drag-and-drop, rubber-banding, etc.+ Updates Model+ Can do limited validity checking, called semantic delegation

- View+ Connection with Controller for feedback+ Connection with Model for back-end data

- Model+ Allows modification of data via user or external events

Jan-24-05 © 2001-2005 by David A. Carr 21 L

Advantages of the MVC Model

• Flexibility- Easier to create multiple views of same model

- Easier to retarget toward multiple platforms

- Easier to integrate external events

Model

Controller View Controller View

Page 8: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 22 L

Example, Spotfire-like Visualization

Jan-24-05 © 2001-2005 by David A. Carr 23 L

Example, Spotfire-like Visualization

• Model ⇒ Data to be visualized

• First, VC pair- View

+ Scatter plot with zoom and pan

+ Visual aspects of controls for filtering

- Controller+ View manipulation, zoom, pan ⇒ View

+ Logic for filtering ⇒ Model

Jan-24-05 © 2001-2005 by David A. Carr 24 L

Adding Details-on-Demand

• Add another VC pair

• View- List the details of a data point

• Controller- Scrolling details

• Selection of point- In First, controller

- Communication through model

Page 9: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 25 L

Adding, More Scatter Plots

• If filters are independent,- Add more VC pairs that are copies of the first VC pair

• If there is only one set of filters- Split the first VC pair into two

+ Scatter plot

+ Filter controls

- Now, replicate Scatter Plot VC

Jan-24-05 © 2001-2005 by David A. Carr 26 L

Modifications to MVC

• Often the view and controller are combined- Microsoft’s Document-View architecture

- Swing’s Model-Delegate architecture

• Reasons- Views and controllers are usually tightly coupled

- Views seldom existed alone

Jan-24-05 © 2001-2005 by David A. Carr 27 L

INSTITUTIONEN FÖRSYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Swing and MVC

Page 10: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 28 L

Model-Delegate Architecture

• Swing implements a derivative MVC architecture call the Model-Delegate architecture

• Characteristics:- View+Controller ⇒ UI Delegate- For each widget a UI Delegate is implemented- For each Delegate there are several pluggable look and feel

styles- Associated with each Delegate is a corresponding Model

Class- Communication between Delegate and Model components is

indirect

Jan-24-05 © 2001-2005 by David A. Carr 29 L

Swing Models

• Indirect Communication- The model “broadcasts” change notifications

- Delegates listen and act appropriately

• Specialization through subclass mechanisms- Custom field verification, etc.

Jan-24-05 © 2001-2005 by David A. Carr 30 L

INSTITUTIONEN FÖRSYSTEMTEKNIK

LULEÅ TEKNISKA UNIVERSITET

Architecture and the Event-Action-State Paradigm

Page 11: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 31 L

UCM Architecture

• Key to event-action-state paradigm is centrallymodeling interface state

• With MVC state is either in the model or the controller(s)• Most architectures combine the View and Controller,

i.e. a User Interface layer• By centralizing Model interfaces with the UI and

centralizing interactions between UI components weintroduce a layer between the UI and the Model

• This is called the UCM architecture- User interface – Control - Model

Jan-24-05 © 2001-2005 by David A. Carr 32 L

UCM Architecture

Control Object

Model Object Model Object Model Object

UI Object UI Object UI ObjectUI Object

UI Layer

Control Layer

Model Layer

Jan-24-05 © 2001-2005 by David A. Carr 33 L

UCM Architecture, Notes

• The UC layers together replace the VC components ofthe MVC architecture- Multiple view require multiple UC components

• While UCM theoretically requires a global state model,independent functions can be decoupled- Parallel (AND-states) don’t have to implemented together

- Events can be use for communication

• Single model is basis

Page 12: The MVC Architecture

Jan-24-05 © 2001-2005 by David A. Carr 34 L

Summary

• Dialog control- Implements UI style, sequencing, & interface-application communication

• Software architecture is used:- To map functions to components- Simplify design and implementation- Based on separation of concerns

• MVC and its variants are:- Used in all modern UI systems- Separates interface issues from the application data- Directly supported by Swing

• UCM can be thought of as:- Combining the VC and then splitting to use a global dialog control model

Jan-24-05 © 2001-2005 by David A. Carr 35 L

Questions?