84
How I Accidentally Discovered MVVM No frameworks, no tricks, just good architectural decisions, come to honestly. 360iDevMin, October 2014

How I Accidentally Discovered MVVM

Embed Size (px)

DESCRIPTION

Slides for my talk, given at 360iDevMin in Greeneville, SC in October of 2014

Citation preview

Page 1: How I Accidentally Discovered MVVM

How I Accidentally Discovered MVVMNo frameworks, no tricks, just good architectural decisions, come to honestly.

360iDevMin, October 2014

Page 2: How I Accidentally Discovered MVVM

Bradford DillonSenior iOS Developer / Mobile Arch [email protected] @jbradforddillon

Page 3: How I Accidentally Discovered MVVM

How I Accidentally Discovered MVVM

Page 4: How I Accidentally Discovered MVVM

Accidentally?

Page 5: How I Accidentally Discovered MVVM

MVVM?

Page 6: How I Accidentally Discovered 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)."

Page 7: How I Accidentally Discovered 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)."

Page 8: How I Accidentally Discovered 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)."

Page 9: How I Accidentally Discovered 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)."

Page 10: How I Accidentally Discovered 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)."

Page 11: How I Accidentally Discovered MVVM
Page 12: How I Accidentally Discovered MVVM

Let’s Just Stick With Plain ol’ MVC

Page 13: How I Accidentally Discovered MVVM

Model View Controller

ControllerView Model

Page 14: How I Accidentally Discovered MVVM

Model View Controller

ControllerView Model

UIViewController

Page 15: How I Accidentally Discovered MVVM

Obligatory Massive View Controller

Slide

Page 16: How I Accidentally Discovered MVVM
Page 17: How I Accidentally Discovered MVVM
Page 18: How I Accidentally Discovered MVVM

Massive View Controller

iPhone VC

A Cautionary Tale

Page 19: How I Accidentally Discovered MVVM

Massive View Controller

iPhone VC Model

A Cautionary Tale

Page 20: How I Accidentally Discovered MVVM

Massive View Controller

iPhone VC

iPad VC

A Cautionary Tale

Page 21: How I Accidentally Discovered MVVM

Massive View Controller

Shared Superclass

iPhone VC

iPad VC

A Cautionary Tale

Page 22: How I Accidentally Discovered MVVM

Massive View Controller

Shared Superclass

iPhone VC

iPad VC

Model

A Cautionary Tale

Page 23: How I Accidentally Discovered MVVM

Massive View Controller

Shared Superclass

iPhone VC

iPad VC

Model

A Cautionary Tale

Page 24: How I Accidentally Discovered MVVM

Massive View Controller

Shared Superclass

iPhone VC

iPad VC

Model

A Cautionary Tale

Page 25: How I Accidentally Discovered MVVM

Massive View Controller

Shared Superclass

iPhone VC

iPad VC

Model

A Cautionary Tale

Page 26: How I Accidentally Discovered MVVM

Massive View Controller

Shared Superclass

iPhone VC

iPad VC

Model

A Cautionary Tale

Page 27: How I Accidentally Discovered MVVM

What do we need?

ControllerView Model

Page 28: How I Accidentally Discovered MVVM

What do we need?

ControllerView Model

???

Page 29: How I Accidentally Discovered MVVM

<Interlude> A Word On Skinning Cats

Page 30: How I Accidentally Discovered MVVM

I SKINNED THE CAT

Page 31: How I Accidentally Discovered MVVM

And now it’s pissed...

Page 32: How I Accidentally Discovered MVVM

“There’s more than one way to skin a cat”

Page 33: How I Accidentally Discovered MVVM
Page 34: How I Accidentally Discovered MVVM
Page 35: How I Accidentally Discovered MVVM

CATS ARE BEAUTIFUL SNOWFLAKES

Page 36: How I Accidentally Discovered MVVM

“I should use X because Y.”

Page 37: How I Accidentally Discovered MVVM

“I should use ASIHTTPRequest because

networking is hard.”

Page 38: How I Accidentally Discovered MVVM

“I need to do Y, and X is the best solution.”

Page 39: How I Accidentally Discovered MVVM

“I need to fetch a single file over HTTP, and _____ is the

best solution.”

Page 40: How I Accidentally Discovered MVVM

</Interlude> Back to the talk…

Page 41: How I Accidentally Discovered MVVM

Design Patterns > Libraries

Page 42: How I Accidentally Discovered MVVM

Brainstorming

iPhone VC

Model

iPad VC

View

View

Page 43: How I Accidentally Discovered MVVM

Brainstorming

iPhone VC

Model

iPad VC

View

View

Page 44: How I Accidentally Discovered MVVM

Brainstorming

iPhone VC

Model

iPad VC

View

View

Page 45: How I Accidentally Discovered MVVM

Brainstorming

iPhone VC

Model

iPad VC

View

View

Page 46: How I Accidentally Discovered MVVM

Brainstorming

iPhone VC

Model

iPad VC

View

View

Page 47: How I Accidentally Discovered MVVM

Brainstorming

iPhone VC

Model

iPad VC

Model Controller

View

View

Page 48: How I Accidentally Discovered MVVM

Concern Separation of MVC Composition Over Inheritance

“Glue” Like UIViewController NSFetchedResultsController

Page 49: How I Accidentally Discovered MVVM

VVCMCM

Page 50: How I Accidentally Discovered MVVM

VVCMCM

Model ControllerView ModelView

Controller

Page 51: How I Accidentally Discovered MVVM

VVCMCM

Shared Superclass

iPhone VC

iPad VC

Model

Page 52: How I Accidentally Discovered MVVM

VVCMCM

iPhone VC

Model

iPad VC

Model Controller

Page 53: How I Accidentally Discovered MVVM

VVCMCM

Model Controller

• Easily Tested • Easily Composed • Easily Refactored • Easily Replaced

Page 54: How I Accidentally Discovered MVVM

VVCMCM

Page 55: How I Accidentally Discovered MVVM

“…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

Page 56: How I Accidentally Discovered MVVM

MVVM

Page 57: How I Accidentally Discovered MVVM

Model-View-ViewModelView

ModelView ModelView Controller

Page 58: How I Accidentally Discovered MVVM

Model-View-ViewModelView

ModelView ModelView Controller

Page 59: How I Accidentally Discovered MVVM

Model-View-ViewModelView

ModelView Model

Page 60: How I Accidentally Discovered MVVM

MVVM

iPhone VC

Model

iPad VC

View Model

Page 61: How I Accidentally Discovered MVVM

VVCMCM

Model Controller

• Easily Tested • Easily Composed • Easily Refactored • Easily Replaced

Page 62: How I Accidentally Discovered MVVM

MVVM

View Model

• Easily Tested • Easily Composed • Easily Refactored • Easily Replaced

Page 63: How I Accidentally Discovered MVVM

MVVM

Page 64: How I Accidentally Discovered MVVM

MVVM

iPhone VC

Model

iPad VC

View Model

Widget VC

Page 65: How I Accidentally Discovered MVVM

Example

Table VC

View Model

Page 66: How I Accidentally Discovered MVVM

Example

Table VC

Table Cell

Table Cell

Table Cell

View Model

Page 67: How I Accidentally Discovered MVVM

Example

Table VC

Table Cell

Table Cell

Table Cell

View Model

View Model

View Model

View Model

Page 68: How I Accidentally Discovered MVVM

Example

Table VC

Table Cell

Table Cell

Table Cell

View Model

View Model

View Model

View Model

Page 69: How I Accidentally Discovered MVVM

Example

Collection VC

Cell Cell

Cell

View Model

Page 70: How I Accidentally Discovered MVVM

Example

Collection VC

Cell Cell

Cell

View Model

View Model

View Model

View Model

Page 71: How I Accidentally Discovered MVVM

Example

Widget VC

View Model

Page 72: How I Accidentally Discovered MVVM

What I Learned About MVVM

Page 73: How I Accidentally Discovered MVVM

What I Learned About MVVM

1. Works Well With MVC.

Page 74: How I Accidentally Discovered MVVM

What I Learned About MVVM

1. Works Well With MVC.2. Naturally Pairs With View Controllers.

Page 75: How I Accidentally Discovered MVVM

What I Learned About MVVM

1. Works Well With MVC.2. Naturally Pairs With View Controllers.3. Allows Better Refactoring and Reuse.

Page 76: How I Accidentally Discovered MVVM

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.

Page 77: How I Accidentally Discovered MVVM

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.

Page 78: How I Accidentally Discovered MVVM

What I Learned About Cats

Page 79: How I Accidentally Discovered MVVM

What I Learned About Cats

1. Avoid Massive View Controllers.

Page 80: How I Accidentally Discovered MVVM

What I Learned About Cats

1. Avoid Massive View Controllers.2. Understand Your Problem and Look for a

Solution to THAT Problem.

Page 81: How I Accidentally Discovered MVVM

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).

Page 82: How I Accidentally Discovered MVVM

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.

Page 83: How I Accidentally Discovered MVVM

Bradford Dillon @jbradforddillon

(bit.ly/tweetford)

Page 84: How I Accidentally Discovered MVVM

Thank you