Participants 1 Model The part that does the actual computation, - - PowerPoint PPT Presentation

participants 1
SMART_READER_LITE
LIVE PREVIEW

Participants 1 Model The part that does the actual computation, - - PowerPoint PPT Presentation

Model View Controller Pattern Behavioural Intent Partition user-interactive applications into three parts > Model > View > Controller Motivation Use divide and conquer to simplify


slide-1
SLIDE 1

MVC-1

Model View Controller Pattern – Behavioural

  • Intent

» Partition user-interactive applications into three

parts

> Model > View > Controller


  • Motivation

» Use divide and conquer to simplify interactions

among the parts of a program

slide-2
SLIDE 2

MVC-2

Participants – 1

  • Model

» The part that does the actual computation, data

manipulation and processing

  • View

» The purely graphical part of the application, taking

care of presenting information visually and interacting with users. Notions such as buttons,

  • ther controls and events belong here
  • Controller

» Connects the model with the view by specifying

what operations from the model must be executed in response to what user events occur

slide-3
SLIDE 3

MVC-3

Participants – 2

  • Controller

Model View

Diagrams based on Stanford CS193p Fall 2011 slides

What your application is Mediates between the model and the view How a user sees and accesses the model

slide-4
SLIDE 4

MVC-4

Communications

  • It’s all about managing the communications

Controller View Model

Model and view never talk directly to each other Controller can always talk to the model and view

  • utlet
slide-5
SLIDE 5

MVC-5

Communications – Model

  • Controller

View Model

Model has a radio station to broadcast
 change notifications

  • Models can only communicate directly with other models

Controllers (and other models) tune into stations in which they are interested

slide-6
SLIDE 6

MVC-6

Communications – View – 1 of 3

  • Target method

Action – button, gesture

Controller View Model

slide-7
SLIDE 7

MVC-7

Communications – View – 2 of 3

  • Controller sets itself as view’s delegate

View asks controller to do work, indirectly as its delegate,
 and notifies the controller when
 the view changes

Controller View Model

should, will, did

slide-8
SLIDE 8

MVC-8

Communications – View – 3 of 3

  • Controller sets itself as view’s data source

View asks controller for the data it needs

Controller View Model

data, at, count

slide-9
SLIDE 9

MVC-9

Multiple MVC patterns

  • Controller

Controller Model Controller View Model Controller View Controller View Model Controller View Model

slide-10
SLIDE 10

MVC-10

Hello World Example

  • Spaceling

No model

sayHelloButton

slide-11
SLIDE 11

MVC-11

Calculator Example

  • delegate for “back” button

data source

If the calculator has the data source protocol expected by the graphing function, then it could be the data source

Calculator_view_controller Function_graph_vc Calculator

slide-12
SLIDE 12

MVC-12

Participants

  • Model

Has all the data and methods for maintaining the data

  • View

Displays relevant data, accepts user actions and notifies controller

  • Controller

» Reacts to changes in the model to instruct how the

view is to change

» Reacts to view “actions” to instruct the view how

to change and to instruct how the model is to change

slide-13
SLIDE 13

MVC-13

Applicability

  • Use MVC in all interactive applications
slide-14
SLIDE 14

MVC-14

Consequences

  • The accepted way to deal with interactive

applications

slide-15
SLIDE 15

MVC-15

Related Patterns

  • MVC is a special case of the Mediator pattern

» The controller is the mediator between the model

and the view

  • MVC has similarities to the Observer pattern.