SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
EMBARCADERO)TECHNOLOGIES)
Introduction to MVVM
in Delphi
With thanks to Malcolm Groves
www.malcolmgroves.com
)
EMBARCADERO)TECHNOLOGIES)
Agenda
•  What’s the problem we’re trying to solve?
•  Different approaches to solving it.
•  MVVM
–  What’s a Model?
–  What’s a View?
–  What’s a View Model?
•  Demo
–  Common Issues
•  Things to think about
•  More Resources
https://github.com/malcolmgroves/menialtasks
EMBARCADERO)TECHNOLOGIES)
Three)types)of)logic)in)an)App)
•  Presenta(on*Logic*
•  Domain*Logic*
•  Data*Access*Logic*
•  Where*you*put*it*all*ma8ers.*A*LOT.*
EMBARCADERO)TECHNOLOGIES)
TradiAonal)Delphi)Approach)
<  Presenta(on*Logic*and*Domain*Logic*mixed*together*
in*On…*events*
<  Data*Access*logic*either*in*Form*or*Data*Modules*or*
both*
Data Access Logic
Presentation Logic
Domain Logic
EMBARCADERO)TECHNOLOGIES)
TradiAonal)Delphi)Approach)
<  Advantages*
<  Quick*to*Develop*
<  Well*understood*
<  Disadvantages*
<  Hard*to*maintain.*Bri8le.*
<  Hard*to*replace*UI*with*a*new*one.*
<  Hard*to*test.*
Data Access Logic
Presentation Logic
Domain Logic
EMBARCADERO)TECHNOLOGIES)
Not)a)new)problem)
•  Lots*of*Presenta(on*Pa8erns*
–  MVC*–*Model<View<Controller*
–  MVP*–*Model<View<Presenter*
–  MVVM*–*Model<View<ViewModel*
•  Based*on*Presenta(on*Model*by*Mar(n*Fowler*
–  In*turn,*based*on*Applica(on*Model*from*SmallTalk*
EMBARCADERO)TECHNOLOGIES)
MVVM)is)about)the)PresentaAon)Layer)
•  Model*is*ignorant*of*Views*and*View*Models*
•  View*Models*are*ignorant*of*Views*
Presenta(on** Domain* Data*Access*
Views*
View*
Models*
Model*
LiveBindings*
EMBARCADERO)TECHNOLOGIES)
MVVM)H)Model)
•  Model*–*Business*Domain*of*your*App*
–  In*iTunes*it’s*all*about*ar(sts,*songs,*plays,*ra(ngs,*etc*
–  In*an*Accoun(ng*App*it’s*Accounts,*Transac(ons,*etc*
–  In*SalesForce*it’s*Customers,*Ac(vi(es,*Forecasts,*Opportuni(es,*etc*
•  Important:*Model*can*be*Unit*Tested!*
*
Presenta(on** Domain* Data*Access*
Views*
View*
Models*
Model*
LiveBindings*
EMBARCADERO)TECHNOLOGIES)
MVVM)–)View)Model)
•  View*Model*–*literally*the*Model*of*your*View*(UI)*
–  The*data*that*is*acted*upon*in*this*View*
–  The*workflows/processes*that*are*invoked*in*this*View*
–  The*UI*rules*that*are*built*into*this*View*
•  Important:*ViewModels*can*be*Unit*Tested!*
Presenta(on** Domain* Data*Access*
Views*
View*
Models*
Model*
LiveBindings*
EMBARCADERO)TECHNOLOGIES)
MVVM)H)View)
•  View*–*The*visual*rendering*of*a*View*Model*
–  LiveBindings*to*bind*the*ViewModel*data*to*the*UI*
–  Minimum*code*needed*to*invoke*methods*in*the*ViewModel*
–  Code*specific*to*THIS*View*
•  Important:*Views*are*hard*to*Unit*Test*
–  So,*the*only*Good*View*is*a*Dumb*View!*
Presenta(on** Domain* Data*Access*
Views*
View*
Models*
Model*
LiveBindings*
EMBARCADERO)TECHNOLOGIES)
MVVM)
•  1*View*has*1*ViewModel*
•  1*ViewModel*might*be*used*by*mul(ple*Views*
Presenta(on** Domain* Data*Access*
Views*
View*
Models*
Model*
LiveBindings*
EMBARCADERO)TECHNOLOGIES)
Quick)Example)Tour)H)MenialTasks)
•  Disclaimers:*
–  Example*is*focused*on*introducing*MVVM,*nothing*else*
–  Purposely*simple*
•  Bare*minimum*of*features*to*show*key*MVVM*topics*
–  No*Persistence*
–  No*IoC*
EMBARCADERO)TECHNOLOGIES)
Example):)AcAons)
•  ViewModel*decides*if*it*is*OK*to*Save*given*the*
current*state*
•  View*decides*how*to*represent*that*in*the*UI,*eg.*
Disabling*the*bu8on*
TTaskView* TTaskViewModel* TTask*
procedure Save;
property CanSave :
boolean
property IsValid:
boolean
EMBARCADERO)TECHNOLOGIES)
*****TMainViewModel******TMainView*
Example:)Displaying)a)child)Form)
1.  At startup, View provides the
ViewModel an Anonymous Method to
call when a Child View is needed
2.  Sometime later, the Add Task button
is clicked
3.  ViewModel creates the child
ViewModel, and calls the Anonymous
Method, passing the child ViewModel
as a parameter
4.  The anonymous method creates the
child View, passing it the child
ViewModel, then shows it.
5.  When the child View closes, the
anonymous method cleans up,
refreshes bindings, etc, as needed.
6.  When the anonymous method
returns, the ViewModel still has
access to the child ViewModel, so
can access its data if required
ViewModel.AddNewTask
OnEditTask returns
OnEditTask invoked
EMBARCADERO)TECHNOLOGIES)
Things)to)think)about:)
–  Pure*Views*
•  The*less*code*you*write*in*your*View,*the*less*there*is*untested*
–  View*First*vs*View*Model*First?*
–  View*<>*Form*
•  A*View*could*be*a*Panel*
•  A*View*could*be*a*wrapper*around*ShowMessage*
EMBARCADERO)TECHNOLOGIES)
Things)to)think)about:)
–  MVVM*doesn’t*dictate*IoC,*but*it*can*simplify*your*code*
and*your*tests.*
–  You*don’t*need*a*MVVM*Framework*
•  But*you’ll*probably*end*up*wri(ng*one.*Everyone*else*does.*
–  Try*it.*Everything*is*clumsy*at*first.*If*MVVM*doesn’t*work*
for*you,*try*MVC,*MVP,*etc.*
EMBARCADERO)TECHNOLOGIES)
More)InformaAon)
•  Series*of*more*detailed*blog*posts*on*MVVM*in*Delphi**
www.malcolmgroves.com*
•  MenialTasks*source*online*at*h8ps://github.com/malcolmgroves****
•  Other*Resources*(list*online*at*h8p://mgrov.es/mvvmlist*)*
–  Books*
•  Developer’s*Guide*to*Microsoc*Prism**
h8p://msdn.microsoc.com/en<us/library/gg406140.aspx*
•  Advanced*MVVM*h8p://amzn.com/B0038KX9FW*
–  Ar(cles*
•  WPF*Apps*with*the*Model<View<ViewModel*Pa8ern*–*Josh*Smith*h8p://msdn.microsoc.com/en<us/magazine/
dd419663.aspx*
–  Videos*
•  Build*Your*Own*MVVM*Framework*–*Rob*Eisenberg*(MIX10*Conference)*
h8p://channel9.msdn.com/Events/MIX/MIX10/EX15*
•  Thank*You!*

Contenu connexe

Similaire à Introduction to mvvm

2013 Toorcon San Diego Building Custom Android Malware for Penetration Testing
2013 Toorcon San Diego Building Custom Android Malware for Penetration Testing2013 Toorcon San Diego Building Custom Android Malware for Penetration Testing
2013 Toorcon San Diego Building Custom Android Malware for Penetration Testing
Stephan Chenette
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)
Oleg Zinchenko
 
Yet another DSL for cross platforms mobile development
Yet another DSL for cross platforms mobile developmentYet another DSL for cross platforms mobile development
Yet another DSL for cross platforms mobile development
Olivier Le Goaër
 
Developing With Openbravo Rl Eppt
Developing With Openbravo Rl EpptDeveloping With Openbravo Rl Eppt
Developing With Openbravo Rl Eppt
vobree
 

Similaire à Introduction to mvvm (20)

Battle of The Mocking Frameworks
Battle of The Mocking FrameworksBattle of The Mocking Frameworks
Battle of The Mocking Frameworks
 
L04 Software Design Examples
L04 Software Design ExamplesL04 Software Design Examples
L04 Software Design Examples
 
What Comes After MBSE Webinar
What Comes After MBSE WebinarWhat Comes After MBSE Webinar
What Comes After MBSE Webinar
 
StackEngine Problem Space Demo
StackEngine Problem Space DemoStackEngine Problem Space Demo
StackEngine Problem Space Demo
 
How to start your open source project
How to start your open source projectHow to start your open source project
How to start your open source project
 
C# in depth
C# in depthC# in depth
C# in depth
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Introduction to architectures based on models, models and metamodels. model d...
Introduction to architectures based on models, models and metamodels. model d...Introduction to architectures based on models, models and metamodels. model d...
Introduction to architectures based on models, models and metamodels. model d...
 
2013 Toorcon San Diego Building Custom Android Malware for Penetration Testing
2013 Toorcon San Diego Building Custom Android Malware for Penetration Testing2013 Toorcon San Diego Building Custom Android Malware for Penetration Testing
2013 Toorcon San Diego Building Custom Android Malware for Penetration Testing
 
RAD Studio XE7 Tour Live Online - Move your VCL Into the Future
RAD Studio XE7 Tour Live Online - Move your VCL Into the FutureRAD Studio XE7 Tour Live Online - Move your VCL Into the Future
RAD Studio XE7 Tour Live Online - Move your VCL Into the Future
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)
 
RAD Studio XE5 in Action Tech Preview
RAD Studio XE5 in Action Tech PreviewRAD Studio XE5 in Action Tech Preview
RAD Studio XE5 in Action Tech Preview
 
How to Perform 21st Century Systems Engineering
How to Perform 21st Century Systems EngineeringHow to Perform 21st Century Systems Engineering
How to Perform 21st Century Systems Engineering
 
Building a Modern Windows App
Building a Modern Windows AppBuilding a Modern Windows App
Building a Modern Windows App
 
The Nuxeo Way: leveraging open source to build a world-class ECM platform
The Nuxeo Way: leveraging open source to build a world-class ECM platformThe Nuxeo Way: leveraging open source to build a world-class ECM platform
The Nuxeo Way: leveraging open source to build a world-class ECM platform
 
Yet another DSL for cross platforms mobile development
Yet another DSL for cross platforms mobile developmentYet another DSL for cross platforms mobile development
Yet another DSL for cross platforms mobile development
 
Pense fora da caixa: Aplique Agilidade com Domain Driven Design. Você ainda u...
Pense fora da caixa: Aplique Agilidade com Domain Driven Design. Você ainda u...Pense fora da caixa: Aplique Agilidade com Domain Driven Design. Você ainda u...
Pense fora da caixa: Aplique Agilidade com Domain Driven Design. Você ainda u...
 
Getting started with docker
Getting started with dockerGetting started with docker
Getting started with docker
 
Developing With Openbravo Rl Eppt
Developing With Openbravo Rl EpptDeveloping With Openbravo Rl Eppt
Developing With Openbravo Rl Eppt
 
Deep Dive into Futures and the Parallel Programming Library
Deep Dive into Futures and the Parallel Programming LibraryDeep Dive into Futures and the Parallel Programming Library
Deep Dive into Futures and the Parallel Programming Library
 

Plus de Embarcadero Technologies

Getting Started Building Mobile Applications for iOS and Android
Getting Started Building Mobile Applications for iOS and AndroidGetting Started Building Mobile Applications for iOS and Android
Getting Started Building Mobile Applications for iOS and Android
Embarcadero Technologies
 

Plus de Embarcadero Technologies (20)

PyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdfPyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdf
 
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
 
Linux GUI Applications on Windows Subsystem for Linux
Linux GUI Applications on Windows Subsystem for LinuxLinux GUI Applications on Windows Subsystem for Linux
Linux GUI Applications on Windows Subsystem for Linux
 
Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework
 
Introduction to Python GUI development with Delphi for Python - Part 1: Del...
Introduction to Python GUI development with Delphi for Python - Part 1:   Del...Introduction to Python GUI development with Delphi for Python - Part 1:   Del...
Introduction to Python GUI development with Delphi for Python - Part 1: Del...
 
FMXLinux Introduction - Delphi's FireMonkey for Linux
FMXLinux Introduction - Delphi's FireMonkey for LinuxFMXLinux Introduction - Delphi's FireMonkey for Linux
FMXLinux Introduction - Delphi's FireMonkey for Linux
 
Python for Delphi Developers - Part 2
Python for Delphi Developers - Part 2Python for Delphi Developers - Part 2
Python for Delphi Developers - Part 2
 
Python for Delphi Developers - Part 1 Introduction
Python for Delphi Developers - Part 1 IntroductionPython for Delphi Developers - Part 1 Introduction
Python for Delphi Developers - Part 1 Introduction
 
RAD Industrial Automation, Labs, and Instrumentation
RAD Industrial Automation, Labs, and InstrumentationRAD Industrial Automation, Labs, and Instrumentation
RAD Industrial Automation, Labs, and Instrumentation
 
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBaseEmbeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
 
Rad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup DocumentRad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup Document
 
TMS Google Mapping Components
TMS Google Mapping ComponentsTMS Google Mapping Components
TMS Google Mapping Components
 
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinar
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinarMove Desktop Apps to the Cloud - RollApp & Embarcadero webinar
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinar
 
Useful C++ Features You Should be Using
Useful C++ Features You Should be UsingUseful C++ Features You Should be Using
Useful C++ Features You Should be Using
 
Getting Started Building Mobile Applications for iOS and Android
Getting Started Building Mobile Applications for iOS and AndroidGetting Started Building Mobile Applications for iOS and Android
Getting Started Building Mobile Applications for iOS and Android
 
Embarcadero RAD server Launch Webinar
Embarcadero RAD server Launch WebinarEmbarcadero RAD server Launch Webinar
Embarcadero RAD server Launch Webinar
 
ER/Studio 2016: Build a Business-Driven Data Architecture
ER/Studio 2016: Build a Business-Driven Data ArchitectureER/Studio 2016: Build a Business-Driven Data Architecture
ER/Studio 2016: Build a Business-Driven Data Architecture
 
The Secrets of SQL Server: Database Worst Practices
The Secrets of SQL Server: Database Worst PracticesThe Secrets of SQL Server: Database Worst Practices
The Secrets of SQL Server: Database Worst Practices
 
Driving Business Value Through Agile Data Assets
Driving Business Value Through Agile Data AssetsDriving Business Value Through Agile Data Assets
Driving Business Value Through Agile Data Assets
 
Troubleshooting Plan Changes with Query Store in SQL Server 2016
Troubleshooting Plan Changes with Query Store in SQL Server 2016Troubleshooting Plan Changes with Query Store in SQL Server 2016
Troubleshooting Plan Changes with Query Store in SQL Server 2016
 

Dernier

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Dernier (20)

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 

Introduction to mvvm