Refining ModelViewController - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Refining ModelViewController

Description:

... can be considered as part of the view; Controls can both present data and handle ... Requires that View has a Read-Only handle to the Model, otherwise it might ... – PowerPoint PPT presentation

Number of Views:110
Avg rating:3.0/5.0
Slides: 12
Provided by: daniel73
Category:

less

Transcript and Presenter's Notes

Title: Refining ModelViewController


1
Refining Model-View-Controller
  • Daniel Chait
  • Partner
  • Lab49, Inc.

2
Classic MVC Pattern
  • Model
  • Domain data objects
  • View
  • Presentation/display
  • Controller
  • Map user inputs to View and Model

3
Example PowerPoint Object Model
Views
Slide Editing View
Outline View
4
Example Contd
Run-Time Characteristics
  • One instance of Model
  • Many View instances, each should update in
    realtime as Model changes
  • Controller? Depends

5
Controller Options
  • Ignore it
  • Traditional job of Controller (Smalltalk-80)
    interpreting mouse/keyboard input has been
    subsumed by the system and is no longer needed
    as such.
  • For simple apps, Controller can be considered as
    part of the view Controls can both present data
    and handle user input. DocumentView in MFC
  • When to use it
  • Aspect-oriented programming need to mediate all
    changes to the model. Examples Undo/Redo,
    Logging, Unit Testing

6
Controller Implementing Undo
  • Command Pattern to change the model
  • Command cmd new ChangeColorCommand(
  • App.Selection.Shapes,
  • Color.Blue)
  • CommandManager.Execute(cmd)
  • Requires that View has a Read-Only handle to the
    Model, otherwise it might circumvent the command
    manager.
  • Undo is then very straightforward
  • if (CommandManager.HasUndo()) CommandManager.Undo(
    )

7
Option1 for tying Model to View
  • Observer/Observable (most common in C/Java)
  • events/delegates
  • App.PresentationAdded Presentation.SlideAdded
    Slide.ShapeAdded events
  • Each model object hooks events of objects below
    it -- Observes them -- and bubbles them
    upwards, eg

Shape1.ColorBlue
Shape1.ColorChanged()
Slide1.ShapeChanged()
Presentation1.Changed()
View1.TitlePresentation1
8
Option2 for tying Model to View
  • Pub/Sub
  • Message bus where events are published and others
    can express interest
  • Makes dependencies explicit and possibly
    declarative
  • Allows aspect-oriented intermediation on event
    level. Examples Event Rollup, Logging,
    Record/Replay

Shape1.ColorBlue
Publish event
TargetShape1PropertyColorOldValRedNewValBlu
e
View1.TitlePresentation1
9
AbstractView The Missing Abstraction
  • Goal is to define the user interface abstractly
    ie. Not in Controls!
  • Models Data such as Open Windows, Current
    Document, Selected Shape
  • Models Events (State Transitions) such as
    WindowOpened/Closed, DocumentActivated,
    SelectionChanged, etc.
  • Allows a very thin UI/Presentation layer to read
    data and watch for events (either via Observer or
    Pub/Sub) with very little logic in it.
  • Easy to change UI or build new UI without
    affecting the underlying interaction model
  • Variously called ViewModel (read Model of the
    View) AbstractView (read An Abstraction of
    the View) PresentationModel (read A Model of
    the Presentation Layer)

10
Further Reading
  • John Gossmans blog blogs.msdn.com/johngossman
  • Talks about how Sparkle is built using
    Model/View/ModelView and then the UI (XAML) is
    attached to the ModelView using pure databinding.
    Nice!
  • Martin Fowler on the Presentation Model
    pattern martinfowler.com/eaaDev/PresentationModel
    .html

11
Questions?
  • Come work at Lab49!
  • Daniel Chait
  • Lab49, Inc.
  • (212) 966-3468 x112
  • daniel_at_lab49.com
  • http//www.lab49.com
Write a Comment
User Comments (0)
About PowerShow.com