SlideShare une entreprise Scribd logo
1  sur  8
The MVVM Pattern




Chris Charabaruk
The Model-View-ViewModel
Pattern
What      Why       How
Architecture design pattern for developing
testable, dynamic applications
Specialization of the Model-View-Controller
and Presentation Model patterns
Often implemented as part of a framework
Three main components: Model, View,
ViewModel
Two support components: Binding,
Commands
The Model-View-ViewModel
Pattern
What     Why       How
Decouple model from application specific
concerns
Simplify work required by developers
Better testability & mocking of programs
Separates behaviour and style of user
interface
The Model-View-ViewModel
Pattern
What             Why               How
Model: business logic and data
    application agnostic
    what the program operates on
View: user interface look & feel
    can be created by designers
    without any programming
ViewModel: adapts model to view
    application logic
    manipulates model
    provides commands & bindings
    to view
Managers: framework
components
    Provide binding & command
    support
Components
Binding   Commands
Bindings are how View and ViewModel stay
synced
Binding manager monitors for property
changes and mirrors them
Bindings can include value converters if View
requires different format than provided by
ViewModel
Components
Binding                        Commands
             ViewModel: property changed                                  View: bound control property changed




           Manager: find property bindings                                   Manager: find binding for control




                Manager: update bindings                                          Manager: update binding
1. Find converter for   2. Run converter on   3. Set bound control   3. Set ViewModel   2. Run converter in   1. Find converter
       binding          new value if needed          property             property       reverse if needed       for binding




       View: bound controls visually updated                                   ViewModel: property updated
Components
Binding     Commands
Commands are how View                View: bound button clicked
passes operations to
ViewModel
Builds on bindings              Manager: execute bound command

  Controls in View can   1. Get command parameter if
                                    set
                                                       2. Run command Execute
                                                                method
  bind to command
  properties on
  ViewModel                               Command: execute

Command manager
informs View of when
commands can be run        ViewModel: update state based on command
Resources
WPF Apps With The Model-View-ViewModel Design
Pattern
  Josh Smith, MSDN Magazine (Feb 2009)
  http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
Introduction to Model/View/ViewModel pattern for
building WPF apps
  John Gossman (8 Oct 2005)
  http://bit.ly/IYlYse
Presentation Model
  Martin Fowler
  http://martinfowler.com/eaaDev/PresentationModel.html

Contenu connexe

Tendances

AngularJS - introduction & how it works?
AngularJS - introduction & how it works?AngularJS - introduction & how it works?
AngularJS - introduction & how it works?Alexe Bogdan
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPFS V
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMMudasir Qazi
 
Introduction To Model View Presenter
Introduction To Model View PresenterIntroduction To Model View Presenter
Introduction To Model View Presentersaeed shargi ghazani
 
Intro to angular
Intro to angularIntro to angular
Intro to angularZach Barnes
 
MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)Yaroslav Voloshyn
 
Web Development with Visual Studio 2012
Web Development with Visual Studio 2012Web Development with Visual Studio 2012
Web Development with Visual Studio 2012Raffaele Fanizzi
 
Technoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesAaron Jacobson
 
Angularjs overview
Angularjs  overviewAngularjs  overview
Angularjs overviewVickyCmd
 
Kalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate
 
Model View Presenter For Android
Model View Presenter For AndroidModel View Presenter For Android
Model View Presenter For AndroidInnovationM
 

Tendances (20)

AngularJS - introduction & how it works?
AngularJS - introduction & how it works?AngularJS - introduction & how it works?
AngularJS - introduction & how it works?
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPF
 
What is MVC?
What is MVC?What is MVC?
What is MVC?
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
Angular JS Introduction
Angular JS IntroductionAngular JS Introduction
Angular JS Introduction
 
Introduction To Model View Presenter
Introduction To Model View PresenterIntroduction To Model View Presenter
Introduction To Model View Presenter
 
Intro to angular
Intro to angularIntro to angular
Intro to angular
 
MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)
 
Angular Seminar-js
Angular Seminar-jsAngular Seminar-js
Angular Seminar-js
 
Web Development with Visual Studio 2012
Web Development with Visual Studio 2012Web Development with Visual Studio 2012
Web Development with Visual Studio 2012
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Technoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development services
 
Angular js
Angular jsAngular js
Angular js
 
Angularjs overview
Angularjs  overviewAngularjs  overview
Angularjs overview
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
Kalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js TutorialsKalp Corporate Angular Js Tutorials
Kalp Corporate Angular Js Tutorials
 
MVVM
MVVMMVVM
MVVM
 
Model View Presenter For Android
Model View Presenter For AndroidModel View Presenter For Android
Model View Presenter For Android
 

En vedette

MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModelDareen Alhiyari
 
Училищен курс по програмиране на C# (2013/2014), занятие №9
Училищен курс по програмиране на C# (2013/2014), занятие №9Училищен курс по програмиране на C# (2013/2014), занятие №9
Училищен курс по програмиране на C# (2013/2014), занятие №9DAVID Academy
 
Anime North 2012 - Katawa Shoujo panel
Anime North 2012 - Katawa Shoujo panelAnime North 2012 - Katawa Shoujo panel
Anime North 2012 - Katawa Shoujo panelChris Charabaruk
 
Училищен курс по програмиране на C# (2013/2014), занятие №7
Училищен курс по програмиране на C# (2013/2014), занятие №7Училищен курс по програмиране на C# (2013/2014), занятие №7
Училищен курс по програмиране на C# (2013/2014), занятие №7DAVID Academy
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHPKacper Gunia
 

En vedette (7)

MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
 
Училищен курс по програмиране на C# (2013/2014), занятие №9
Училищен курс по програмиране на C# (2013/2014), занятие №9Училищен курс по програмиране на C# (2013/2014), занятие №9
Училищен курс по програмиране на C# (2013/2014), занятие №9
 
Gamification
GamificationGamification
Gamification
 
Anime North 2012 - Katawa Shoujo panel
Anime North 2012 - Katawa Shoujo panelAnime North 2012 - Katawa Shoujo panel
Anime North 2012 - Katawa Shoujo panel
 
Здравей, Swift (Hello, Swift)
Здравей, Swift (Hello, Swift)Здравей, Swift (Hello, Swift)
Здравей, Swift (Hello, Swift)
 
Училищен курс по програмиране на C# (2013/2014), занятие №7
Училищен курс по програмиране на C# (2013/2014), занятие №7Училищен курс по програмиране на C# (2013/2014), занятие №7
Училищен курс по програмиране на C# (2013/2014), занятие №7
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
 

Similaire à The MVVM Pattern

Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patternseleksdev
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)Jonathan Engelsma
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10Bryan Anderson
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderSimon Massey
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: AndroidJitendra Kumar
 
Code Camp 06 Model View Presenter Architecture
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecturebitburner93
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSJinkyu Kim
 
Android DesignArchitectures.pptx
Android DesignArchitectures.pptxAndroid DesignArchitectures.pptx
Android DesignArchitectures.pptxSafnaSaff1
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentationBhavin Shah
 
Introduction To MVVM
Introduction To MVVMIntroduction To MVVM
Introduction To MVVMBoulos Dib
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
Introduction to Zend Framework 2
Introduction to Zend Framework 2Introduction to Zend Framework 2
Introduction to Zend Framework 2John Coggeshall
 
реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработкеProvectus
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Arunangsu Sahu
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 

Similaire à The MVVM Pattern (20)

Eclipse MVC
Eclipse MVCEclipse MVC
Eclipse MVC
 
Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patterns
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-Binder
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
Code Camp 06 Model View Presenter Architecture
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecture
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
 
Android DesignArchitectures.pptx
Android DesignArchitectures.pptxAndroid DesignArchitectures.pptx
Android DesignArchitectures.pptx
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
Introduction To MVVM
Introduction To MVVMIntroduction To MVVM
Introduction To MVVM
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
MVC in PHP
MVC in PHPMVC in PHP
MVC in PHP
 
Introduction to Zend Framework 2
Introduction to Zend Framework 2Introduction to Zend Framework 2
Introduction to Zend Framework 2
 
реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработке
 
MVC 4
MVC 4MVC 4
MVC 4
 
AngularJs
AngularJsAngularJs
AngularJs
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 

Dernier

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

The MVVM Pattern

  • 2. The Model-View-ViewModel Pattern What Why How Architecture design pattern for developing testable, dynamic applications Specialization of the Model-View-Controller and Presentation Model patterns Often implemented as part of a framework Three main components: Model, View, ViewModel Two support components: Binding, Commands
  • 3. The Model-View-ViewModel Pattern What Why How Decouple model from application specific concerns Simplify work required by developers Better testability & mocking of programs Separates behaviour and style of user interface
  • 4. The Model-View-ViewModel Pattern What Why How Model: business logic and data application agnostic what the program operates on View: user interface look & feel can be created by designers without any programming ViewModel: adapts model to view application logic manipulates model provides commands & bindings to view Managers: framework components Provide binding & command support
  • 5. Components Binding Commands Bindings are how View and ViewModel stay synced Binding manager monitors for property changes and mirrors them Bindings can include value converters if View requires different format than provided by ViewModel
  • 6. Components Binding Commands ViewModel: property changed View: bound control property changed Manager: find property bindings Manager: find binding for control Manager: update bindings Manager: update binding 1. Find converter for 2. Run converter on 3. Set bound control 3. Set ViewModel 2. Run converter in 1. Find converter binding new value if needed property property reverse if needed for binding View: bound controls visually updated ViewModel: property updated
  • 7. Components Binding Commands Commands are how View View: bound button clicked passes operations to ViewModel Builds on bindings Manager: execute bound command Controls in View can 1. Get command parameter if set 2. Run command Execute method bind to command properties on ViewModel Command: execute Command manager informs View of when commands can be run ViewModel: update state based on command
  • 8. Resources WPF Apps With The Model-View-ViewModel Design Pattern Josh Smith, MSDN Magazine (Feb 2009) http://msdn.microsoft.com/en-us/magazine/dd419663.aspx Introduction to Model/View/ViewModel pattern for building WPF apps John Gossman (8 Oct 2005) http://bit.ly/IYlYse Presentation Model Martin Fowler http://martinfowler.com/eaaDev/PresentationModel.html

Notes de l'éditeur

  1. Today’s presentation is a summary of findings from the article “WPF Apps With The Model-View-ViewModel Design Pattern” by Josh Smith, published in the Feb 2009 issue of MSDN Magazine.We will cover the what, why, and how of the Model-View-ViewModel architectural pattern, with detail of what happens inside MVVM frameworks.
  2. Design patterns are formalized solutions for common problems in software design and development.MVC and PM are two other patterns for building applications with the same separation of concerns as MVVM. These days MVC is best known as the architecture pattern behind the Ruby on Rails framework for web development.MVVM is an integral part of Windows Presentation Foundation in .NET, and the Silverlight platform from Microsoft. As well, MVVM frameworks exist for other platforms and languages.The pattern components will be explained shortly.
  3. MVVM provides developers the ability to separate different parts of an application from each other, which promotes reusability of code and easier testing.Being able to reuse the model layer of the application means that other apps working with the same data do not need to reinvent the wheel.Decoupling also makes it easier to test the different components of the application, as “mock” objects and data can be used to ensure that code runs the way it was designed to do so.Finally, this decoupling makes it easy to change how the application looks, without affecting how it behaves, and vice versa.
  4. Model layer provides business logic and dataLayer could be external to the app, such as web servicesModel code could be shared between applications, so important to keep it free of application-specific concernsView is user interfaceHow the user sees the application – look & feel / styleData from model is represented here, changes reflected back to the modelCan be created with little or no code by UX designersViewModel provides application behaviourLoosely binds model and view through commands and bindingsPushes model updates to view and vice versaSingle ViewModel could work with multiple viewsBulk of application codeManagers provide pattern and framework supportBinding manager automates process of reflecting changes between View and ViewModelCommand manager allows ViewModel to state when commands may or may not be sent by ViewNeither are necessary in the pattern but help greatly
  5. Bindings are defined in the View, and are set up by the binding manager when the view is loaded.Binding manager subscribes to property change events on the ViewModel, and control value change events on the View, so it knows when values need to be updated.Binding objects tell the binding manager which properties of the ViewModel are linked to which properties on the View and its controls.Bindings can contain other special objects, converters, which allow properties on the ViewModel to be converted to formats better supported by the View controls and vice versa.
  6. ViewModel to View example:Property changes in ViewModel. ViewModel fires a property changed event.Binding manager determines which property changed based on the arguments of the event, and finds all the bindings connected to that property.Manager updates each binding, by:Checking if the binding uses a converter, and passing the property’s new value through it if so.Setting the appropriate property on the View with the new or converted value.Control on the View informs the View that it needs to be redrawn, and is visually updated.View to ViewModel example:Property changes in bound control in View. Control fires a value changed event.Binding manager finds the binding attached to that control property.Manager updates the binding, by:Checking if the binding uses a converter, and passes the control value through it if so.Setting the appropriate property on the ViewModel with the new or converted value.ViewModel property is updated, firing off the previous example’s chain of events.
  7. Commands are special objects which provide a View the opportunity to tell the ViewModel to run certain operations, without needing to write any code in the View itself.Command objects are bound like any other property, but are handled specially by the command manager.Commands include an event specifying that whether or not they can be run has changed. This event is handled by the command manager itself, so it can enable or disable command-bound controls.Example:“Save” button on View is clicked. Command manager observes the OnClick event for the button and is informed that it has been clicked.Command manager accesses the command bound to the button, as well as any special parameter for the command set on the button control.Command manager tells the command to run, passing in the parameter if it exists.The command runs, calling certain methods in the ViewModel itself. In this example, the ViewModel updates a specific Model object and tells it to save its data.
  8. The following articles provide more in-depth information on the MVVM pattern and the PM pattern from which it derives. John Gossman is the inventer of MVVM, and Martin Fowler the inventor of PM.Any questions?