Download presentation
Presentation is loading. Please wait.
1
Winter 2012ACS-3913 Ron McFadyen1 Model View Controller Originated with Smalltalk development (1979) Separates a system’s classes into View, Controller, Model
2
Model View Controller ViewController Controller handles decisions regarding user events Model notifies its views Controller informs model to update itself according to user actions Other patterns are likely in use: Factory for creating a default controller Decorator for creating scrollable views … gets updates Winter 20122ACS-3913 Ron McFadyen
3
Model View Controller ViewController Strategy Model Composite Observer Winter 20123ACS-3913 Ron McFadyen
4
Winter 2012ACS-3913 Ron McFadyen4 Model View Controller Whenever the model’s state changes it notifies the view and the view can update itself. The model is a subject that notifies its observers (view) The controller represents a strategy for reacting to user interface events. A view has a controller, a strategy, associated with it; strategies can be swapped in and out. The controller, learning of a certain user action, may inform the model to take some action to update itself. The controller may also inform the view to take some action. The visual presentation is de- coupled from the actions required to manage user gui events. A view is typically a nested structure of components organized according to the composite pattern.
5
Winter 2012ACS-3913 Ron McFadyen5 Model View Controller Examples: Calculator example DJ example in text
6
Winter 2012ACS-3913 Ron McFadyen6 Model View Controller Calculator example (see course web pages) View: To display a log of operations To display running total and allow user to enter an operand and select an operator Model: the current state … the current total Informs the views of pertinent results Controller: Informs the model if the user selects an operator Informs views to update their display
7
Winter 2012ACS-3913 Ron McFadyen7 Model View Controller Assignment 5: modify this example to include a new view more operations (subtraction, division) one list of observers. Due Tuesday April 3, 2012
8
Winter 2012ACS-3913 Ron McFadyen8 Model View Controller DJ example in text, pages 534-544 View: To display a pulsing beat (BeatBar) To display the beats per minute, and to let the user change the bpm in three ways: new value, increment, decrement Model: the current state … the current bpm Informs the views of pertinent changes Controller: Informs the model if the user changes the bpm Informs views to enable/disable buttons Note the controller interface could be described by use cases … one for each end-user goal
9
Winter 2012ACS-3913 Ron McFadyen9 Model View Controller MVC in practice is encountered in many variations on many platforms: e.g. these links may still be valid: http://www.asp.net/mvc/whatisaspmvc http://www.bit-101.com/blog/?p=1969 http://www.silverlightshow.net/items/WP7-for-iPhone-and- Android-Developers-MVC-and-MVVM.aspx
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.