how i accidentally discovered mvvm
DESCRIPTION
Slides for my talk, given at 360iDevMin in Greeneville, SC in October of 2014TRANSCRIPT
How I Accidentally Discovered MVVMNo frameworks, no tricks, just good architectural decisions, come to honestly.
360iDevMin, October 2014
Bradford DillonSenior iOS Developer / Mobile Arch [email protected] @jbradforddillon
How I Accidentally Discovered MVVM
Accidentally?
MVVM?
"The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of
the Presentation Model design pattern introduced by Martin Fowler. Largely based on the model–view–controller pattern (MVC), MVVM is a specific
implementation targeted at UI development platforms which support the event-driven programming in Windows Presentation Foundation (WPF) and
Silverlight on the .NET platforms using XAML and .NET languages. Technically different, but similar, Presentation Model design patterns are
available in HTML5 through AngularJS, KnockoutJS, Ext JS, Vue.js, and for Java the ZK framework (Model-View-Binder)."
"The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of
the Presentation Model design pattern introduced by Martin Fowler. Largely based on the model–view–controller pattern (MVC), MVVM is a specific
implementation targeted at UI development platforms which support the event-driven programming in Windows Presentation Foundation (WPF) and
Silverlight on the .NET platforms using XAML and .NET languages. Technically different, but similar, Presentation Model design patterns are
available in HTML5 through AngularJS, KnockoutJS, Ext JS, Vue.js, and for Java the ZK framework (Model-View-Binder)."
"The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of
the Presentation Model design pattern introduced by Martin Fowler. Largely based on the model–view–controller pattern (MVC), MVVM is a specific
implementation targeted at UI development platforms which support the event-driven programming in Windows Presentation Foundation (WPF) and
Silverlight on the .NET platforms using XAML and .NET languages. Technically different, but similar, Presentation Model design patterns are
available in HTML5 through AngularJS, KnockoutJS, Ext JS, Vue.js, and for Java the ZK framework (Model-View-Binder)."
"The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of
the Presentation Model design pattern introduced by Martin Fowler. Largely based on the model–view–controller pattern (MVC), MVVM is a specific
implementation targeted at UI development platforms which support the event-driven programming in Windows Presentation Foundation (WPF) and
Silverlight on the .NET platforms using XAML and .NET languages. Technically different, but similar, Presentation Model design patterns are
available in HTML5 through AngularJS, KnockoutJS, Ext JS, Vue.js, and for Java the ZK framework (Model-View-Binder)."
"The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of
the Presentation Model design pattern introduced by Martin Fowler. Largely based on the model–view–controller pattern (MVC), MVVM is a specific
implementation targeted at UI development platforms which support the event-driven programming in Windows Presentation Foundation (WPF) and
Silverlight on the .NET platforms using XAML and .NET languages. Technically different, but similar, Presentation Model design patterns are
available in HTML5 through AngularJS, KnockoutJS, Ext JS, Vue.js, and for Java the ZK framework (Model-View-Binder)."
Let’s Just Stick With Plain ol’ MVC
Model View Controller
ControllerView Model
Model View Controller
ControllerView Model
UIViewController
Obligatory Massive View Controller
Slide
Massive View Controller
iPhone VC
A Cautionary Tale
Massive View Controller
iPhone VC Model
A Cautionary Tale
Massive View Controller
iPhone VC
iPad VC
A Cautionary Tale
Massive View Controller
Shared Superclass
iPhone VC
iPad VC
A Cautionary Tale
Massive View Controller
Shared Superclass
iPhone VC
iPad VC
Model
A Cautionary Tale
Massive View Controller
Shared Superclass
iPhone VC
iPad VC
Model
A Cautionary Tale
Massive View Controller
Shared Superclass
iPhone VC
iPad VC
Model
A Cautionary Tale
Massive View Controller
Shared Superclass
iPhone VC
iPad VC
Model
A Cautionary Tale
Massive View Controller
Shared Superclass
iPhone VC
iPad VC
Model
A Cautionary Tale
What do we need?
ControllerView Model
What do we need?
ControllerView Model
???
<Interlude> A Word On Skinning Cats
I SKINNED THE CAT
And now it’s pissed...
“There’s more than one way to skin a cat”
CATS ARE BEAUTIFUL SNOWFLAKES
“I should use X because Y.”
“I should use ASIHTTPRequest because
networking is hard.”
“I need to do Y, and X is the best solution.”
“I need to fetch a single file over HTTP, and _____ is the
best solution.”
</Interlude> Back to the talk…
Design Patterns > Libraries
Brainstorming
iPhone VC
Model
iPad VC
View
View
Brainstorming
iPhone VC
Model
iPad VC
View
View
Brainstorming
iPhone VC
Model
iPad VC
View
View
Brainstorming
iPhone VC
Model
iPad VC
View
View
Brainstorming
iPhone VC
Model
iPad VC
View
View
Brainstorming
iPhone VC
Model
iPad VC
Model Controller
View
View
Concern Separation of MVC Composition Over Inheritance
“Glue” Like UIViewController NSFetchedResultsController
VVCMCM
VVCMCM
Model ControllerView ModelView
Controller
VVCMCM
Shared Superclass
iPhone VC
iPad VC
Model
VVCMCM
iPhone VC
Model
iPad VC
Model Controller
VVCMCM
Model Controller
• Easily Tested • Easily Composed • Easily Refactored • Easily Replaced
VVCMCM
“…an augmented version of MVC where we formally connect the view and controller, and move presentation logic out of the controller
and into a new object, the view model.” Ash Furrow, June 2014
MVVM
Model-View-ViewModelView
ModelView ModelView Controller
Model-View-ViewModelView
ModelView ModelView Controller
Model-View-ViewModelView
ModelView Model
MVVM
iPhone VC
Model
iPad VC
View Model
VVCMCM
Model Controller
• Easily Tested • Easily Composed • Easily Refactored • Easily Replaced
MVVM
View Model
• Easily Tested • Easily Composed • Easily Refactored • Easily Replaced
MVVM
MVVM
iPhone VC
Model
iPad VC
View Model
Widget VC
Example
Table VC
View Model
Example
Table VC
Table Cell
Table Cell
Table Cell
View Model
Example
Table VC
Table Cell
Table Cell
Table Cell
View Model
View Model
View Model
View Model
Example
Table VC
Table Cell
Table Cell
Table Cell
View Model
View Model
View Model
View Model
Example
Collection VC
Cell Cell
Cell
View Model
Example
Collection VC
Cell Cell
Cell
View Model
View Model
View Model
View Model
Example
Widget VC
View Model
What I Learned About MVVM
What I Learned About MVVM
1. Works Well With MVC.
What I Learned About MVVM
1. Works Well With MVC.2. Naturally Pairs With View Controllers.
What I Learned About MVVM
1. Works Well With MVC.2. Naturally Pairs With View Controllers.3. Allows Better Refactoring and Reuse.
What I Learned About MVVM
1. Works Well With MVC.2. Naturally Pairs With View Controllers.3. Allows Better Refactoring and Reuse.4. Helps Avoid Massive View Controllers.
What I Learned About MVVM
1. Works Well With MVC.2. Naturally Pairs With View Controllers.3. Allows Better Refactoring and Reuse.4. Helps Avoid Massive View Controllers.5. Unit Testable.
What I Learned About Cats
What I Learned About Cats
1. Avoid Massive View Controllers.
What I Learned About Cats
1. Avoid Massive View Controllers.2. Understand Your Problem and Look for a
Solution to THAT Problem.
What I Learned About Cats
1. Avoid Massive View Controllers.2. Understand Your Problem and Look for a
Solution to THAT Problem.3. (Sometimes That Solution is a
Bandwagon).
What I Learned About Cats
1. Avoid Massive View Controllers.2. Understand Your Problem and Look for a
Solution to THAT Problem.3. (Sometimes That Solution is a
Bandwagon).4. Good Architecture is Future-Proof.
Thank you