Mobile architecture problems and solutions.

P
Mobile Architecture
Chris Jimenez
Mobile Architecture
En el principio de los tiempos...
MVC
Cons
◦ Massive View Controller!
◦ Sometimes hard to test
◦ More “layers” are needed as app
grows
◦ Its an “Apple thing”
◦ Decrease code clarity
◦ There are better design
patterns
What better you say?
MVVM - Model View View Model
--iOS
MVP - Model View Presenter
--Android
MVVM
◦ View controllers are technically
distinct components, they
almost always go hand-in-hand
together, paired
◦ When is the last time that a
view could be paired with
different view controllers??
MVVM
So why not formalize their
connection?
MVVM
◦ Most of the stuff in
ViewController is presentation
logic
◦ Things like transforming values
from the model into something
the view can present
MVVM
MVVM to the rescue
MVVM
MVVM is 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.
MVVM
Why?
◦ Reduces the complexity of one’s
view controllers and makes
one’s presentation logic easier
to test
Some Code
@interface Person : NSObject
- (instancetype)initwithSalutation:(NSString *)salutation firstName:(NSString
*)firstName lastName:(NSString *)lastName birthdate:(NSDate *)birthdate;
@property (nonatomic, readonly) NSString *salutation;
@property (nonatomic, readonly) NSString *firstName;
@property (nonatomic, readonly) NSString *lastName;
@property (nonatomic, readonly) NSDate *birthdate;
@end
PersonViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
if (self.model.salutation.length > 0) {
self.nameLabel.text = [NSString stringWithFormat:@"%@ %@ %@", self.model.salutation,
self.model.firstName, self.model.lastName];
} else {
self.nameLabel.text = [NSString stringWithFormat:@"%@ %@", self.model.firstName,
self.model.lastName];
}
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE MMMM d, yyyy"];
self.birthdateLabel.text = [dateFormatter stringFromDate:model.birthdate];
}
Now with MVVM, PersonViewModel.h
@interface PersonViewModel : NSObject
- (instancetype)initWithPerson:(Person *)person;
@property (nonatomic, readonly) Person *person;
@property (nonatomic, readonly) NSString *nameText;
@property (nonatomic, readonly) NSString *birthdateText;
@end
PersonViewModel.m
@implementation PersonViewModel
- (instancetype)initWithPerson:(Person *)person {
self = [super init];
if (!self) return nil;
_person = person;
if (person.salutation.length > 0) {
_nameText = [NSString stringWithFormat:@"%@ %@ %@", self.person.salutation,
self.person.firstName, self.person.lastName];
} else {
_nameText = [NSString stringWithFormat:@"%@ %@", self.person.firstName,
self.person.lastName];
}
An our view controller
- (void)viewDidLoad {
[super viewDidLoad];
self.nameLabel.text = self.viewModel.nameText;
self.birthdateLabel.text = self.viewModel.birthdateText;
}
MVVM
Chiva!
MVP Model View Presenter
Presenter is a layer that provides
View with data from Model.
Presenter also handles
background tasks.
Why?
◦ Keep it stupid simple
◦ Removes complexity
◦ Easy to test
Normal View Model in Android
On top of that
◦ View can disappear and appear
at random time
◦ Do not forget about
saving/restoring of Views
◦ Attach a couple of background
tasks to that temporary Views
Model View Presenter
MVP Pros
◦ Complex tasks are split into
simpler tasks and are easier to
solve.
◦ Smaller objects, less bugs,
easier to debug.
◦ Testable.
MVP Background Tasks
Background Tasks
Code time
1 of 25

Recommended

Spine js & creating non blocking user interfaces by
Spine js & creating non blocking user interfacesSpine js & creating non blocking user interfaces
Spine js & creating non blocking user interfacesHjörtur Hilmarsson
1.3K views27 slides
Model-View-Controller: Tips&Tricks by
Model-View-Controller: Tips&TricksModel-View-Controller: Tips&Tricks
Model-View-Controller: Tips&TricksCiklum Ukraine
602 views37 slides
Angular JS lecture by
Angular JS lectureAngular JS lecture
Angular JS lectureCooper Thompson
1K views5 slides
Sencha TouchのMVCについて 〜スケールするアプリケーションを求めて〜 by
Sencha TouchのMVCについて 〜スケールするアプリケーションを求めて〜Sencha TouchのMVCについて 〜スケールするアプリケーションを求めて〜
Sencha TouchのMVCについて 〜スケールするアプリケーションを求めて〜yoshiaki iwanaga
7K views39 slides
Knockout.js presentation by
Knockout.js presentationKnockout.js presentation
Knockout.js presentationScott Messinger
2.5K views24 slides
Nette <3 Webpack by
Nette <3 WebpackNette <3 Webpack
Nette <3 WebpackJiří Pudil
628 views34 slides

More Related Content

What's hot

Ember js getting started by
Ember js getting startedEmber js getting started
Ember js getting startedthetravellingbard
1.7K views40 slides
BDOTNET AngularJs Directives - Uday by
BDOTNET AngularJs Directives - UdayBDOTNET AngularJs Directives - Uday
BDOTNET AngularJs Directives - UdayUdaya Kumar
895 views14 slides
JavaScript Modules in Practice by
JavaScript Modules in PracticeJavaScript Modules in Practice
JavaScript Modules in PracticeMaghdebura
1.4K views25 slides
Advanced Tips & Tricks for using Angular JS by
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSSimon Guest
19.4K views70 slides
AngularJS: an introduction by
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introductionLuigi De Russis
1K views51 slides
AngularJS: Overview & Key Features by
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesMohamad Al Asmar
1.6K views38 slides

What's hot(7)

BDOTNET AngularJs Directives - Uday by Udaya Kumar
BDOTNET AngularJs Directives - UdayBDOTNET AngularJs Directives - Uday
BDOTNET AngularJs Directives - Uday
Udaya Kumar895 views
JavaScript Modules in Practice by Maghdebura
JavaScript Modules in PracticeJavaScript Modules in Practice
JavaScript Modules in Practice
Maghdebura1.4K views
Advanced Tips & Tricks for using Angular JS by Simon Guest
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
Simon Guest19.4K views
AngularJS: Overview & Key Features by Mohamad Al Asmar
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key Features
Mohamad Al Asmar1.6K views
Introduction to javascript templating using handlebars.js by Mindfire Solutions
Introduction to javascript templating using handlebars.jsIntroduction to javascript templating using handlebars.js
Introduction to javascript templating using handlebars.js
Mindfire Solutions2.8K views

Viewers also liked

Good bye Massive View Controller! by
Good bye Massive View Controller!Good bye Massive View Controller!
Good bye Massive View Controller!Supercharge
766 views30 slides
iOS Swift application architecture by
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architectureRomain Rochegude
1.2K views38 slides
Intro to iOS Application Architecture by
Intro to iOS Application ArchitectureIntro to iOS Application Architecture
Intro to iOS Application ArchitectureMake School
1.5K views32 slides
Fronteer Strategy Presentation on Sustainability and Co-creation by
Fronteer Strategy Presentation on Sustainability and Co-creationFronteer Strategy Presentation on Sustainability and Co-creation
Fronteer Strategy Presentation on Sustainability and Co-creationFronteer Strategy
1.9K views56 slides
Introduction to Co-creation (MA Brand Development at Goldsmiths) by
Introduction to Co-creation (MA Brand Development at Goldsmiths)Introduction to Co-creation (MA Brand Development at Goldsmiths)
Introduction to Co-creation (MA Brand Development at Goldsmiths)Felix Koch
3.7K views61 slides
Fronteer Strategy NPOX Co-Creation by
Fronteer Strategy NPOX Co-CreationFronteer Strategy NPOX Co-Creation
Fronteer Strategy NPOX Co-CreationFronteer Strategy
2.3K views67 slides

Viewers also liked(20)

Good bye Massive View Controller! by Supercharge
Good bye Massive View Controller!Good bye Massive View Controller!
Good bye Massive View Controller!
Supercharge766 views
iOS Swift application architecture by Romain Rochegude
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
Romain Rochegude1.2K views
Intro to iOS Application Architecture by Make School
Intro to iOS Application ArchitectureIntro to iOS Application Architecture
Intro to iOS Application Architecture
Make School1.5K views
Fronteer Strategy Presentation on Sustainability and Co-creation by Fronteer Strategy
Fronteer Strategy Presentation on Sustainability and Co-creationFronteer Strategy Presentation on Sustainability and Co-creation
Fronteer Strategy Presentation on Sustainability and Co-creation
Fronteer Strategy1.9K views
Introduction to Co-creation (MA Brand Development at Goldsmiths) by Felix Koch
Introduction to Co-creation (MA Brand Development at Goldsmiths)Introduction to Co-creation (MA Brand Development at Goldsmiths)
Introduction to Co-creation (MA Brand Development at Goldsmiths)
Felix Koch3.7K views
Social Sustainability In Cities by tudorgeog
Social Sustainability In CitiesSocial Sustainability In Cities
Social Sustainability In Cities
tudorgeog2.8K views
An introduction to Mobile Development (Spanish) by PiXeL16
An introduction to Mobile Development (Spanish)An introduction to Mobile Development (Spanish)
An introduction to Mobile Development (Spanish)
PiXeL16434 views
Deferred object by PiXeL16
Deferred objectDeferred object
Deferred object
PiXeL16524 views
Unit testing by PiXeL16
Unit testingUnit testing
Unit testing
PiXeL16545 views
DevOps and Chef by PiXeL16
DevOps and ChefDevOps and Chef
DevOps and Chef
PiXeL16477 views
iOS 7 by PiXeL16
iOS 7 iOS 7
iOS 7
PiXeL16483 views
The Internet own boy by PiXeL16
The Internet own boyThe Internet own boy
The Internet own boy
PiXeL16536 views
Indoor Positioning System with iBeacons by PiXeL16
Indoor Positioning System with iBeaconsIndoor Positioning System with iBeacons
Indoor Positioning System with iBeacons
PiXeL16605 views
WWDC 2014 by PiXeL16
WWDC 2014WWDC 2014
WWDC 2014
PiXeL16512 views
Designing for social sustainability, presentation to RTPI Scotland 7th Octobe... by social_life_presentations
Designing for social sustainability, presentation to RTPI Scotland 7th Octobe...Designing for social sustainability, presentation to RTPI Scotland 7th Octobe...
Designing for social sustainability, presentation to RTPI Scotland 7th Octobe...
Social Sustainability In Cities by tudorgeog
Social Sustainability In CitiesSocial Sustainability In Cities
Social Sustainability In Cities
tudorgeog4.1K views
REST with Eve and Python by PiXeL16
REST with Eve and PythonREST with Eve and Python
REST with Eve and Python
PiXeL161.9K views
Make School 2017 - Mastering iOS Development by Make School
Make School 2017 - Mastering iOS DevelopmentMake School 2017 - Mastering iOS Development
Make School 2017 - Mastering iOS Development
Make School2.6K views

Similar to Mobile architecture problems and solutions.

Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев by
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис ЛебедевВстреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис ЛебедевCocoaHeads
1.3K views46 slides
Valentine with AngularJS by
Valentine with AngularJSValentine with AngularJS
Valentine with AngularJSVidyasagar Machupalli
987 views43 slides
Fundaments of Knockout js by
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout jsFlavius-Radu Demian
2.4K views44 slides
MVP Mix 2015 Leveraging MVVM on all Platforms by
MVP Mix 2015  Leveraging MVVM on all PlatformsMVP Mix 2015  Leveraging MVVM on all Platforms
MVP Mix 2015 Leveraging MVVM on all PlatformsJames Montemagno
832 views39 slides
Training: MVVM Pattern by
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM PatternBetclic Everest Group Tech Team
26.5K views29 slides
iOS 101 - Xcode, Objective-C, iOS APIs by
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsSubhransu Behera
4.1K views43 slides

Similar to Mobile architecture problems and solutions.(20)

Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев by CocoaHeads
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис ЛебедевВстреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
CocoaHeads1.3K views
MVP Mix 2015 Leveraging MVVM on all Platforms by James Montemagno
MVP Mix 2015  Leveraging MVVM on all PlatformsMVP Mix 2015  Leveraging MVVM on all Platforms
MVP Mix 2015 Leveraging MVVM on all Platforms
James Montemagno832 views
iOS 101 - Xcode, Objective-C, iOS APIs by Subhransu Behera
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
Subhransu Behera4.1K views
Asp.NET MVC by vrluckyin
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
vrluckyin436 views
MV* presentation frameworks in Javascript: en garde, pret, allez! by Roberto Messora
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!
Roberto Messora1K views
Introduction to Knockout Js by Knoldus Inc.
Introduction to Knockout JsIntroduction to Knockout Js
Introduction to Knockout Js
Knoldus Inc.1.8K views
深入淺出 MVC by Jace Ju
深入淺出 MVC深入淺出 MVC
深入淺出 MVC
Jace Ju20.8K views
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin by Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Barry Gervin1.4K views
02.Designing Windows Phone Application by Nguyen Tuan
02.Designing Windows Phone Application02.Designing Windows Phone Application
02.Designing Windows Phone Application
Nguyen Tuan427 views
Spring MVC Intro / Gore - Nov NHJUG by Ted Pennings
Spring MVC Intro / Gore - Nov NHJUGSpring MVC Intro / Gore - Nov NHJUG
Spring MVC Intro / Gore - Nov NHJUG
Ted Pennings1.5K views
10 tips for a reusable architecture by Jorge Ortiz
10 tips for a reusable architecture10 tips for a reusable architecture
10 tips for a reusable architecture
Jorge Ortiz7.4K views
Building an enterprise app in silverlight 4 and NHibernate by bwullems
Building an enterprise app in silverlight 4 and NHibernateBuilding an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernate
bwullems2.2K views
Asp.net mvc training by icubesystem
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
icubesystem603 views
AngularJS in 60ish Minutes by Dan Wahlin
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
Dan Wahlin16.5K views
Protocol-Oriented MVVM (extended edition) by Natasha Murashev
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)
Natasha Murashev5.2K views

More from PiXeL16

Hooked - How to build habit forming products by
Hooked - How to build habit forming products Hooked - How to build habit forming products
Hooked - How to build habit forming products PiXeL16
802 views49 slides
WWDC 2016 by
WWDC 2016WWDC 2016
WWDC 2016PiXeL16
582 views36 slides
Resposive design (Esli David) by
Resposive design (Esli David)Resposive design (Esli David)
Resposive design (Esli David)PiXeL16
375 views10 slides
Estandares de Codigo (Emanuel) by
Estandares de Codigo (Emanuel)Estandares de Codigo (Emanuel)
Estandares de Codigo (Emanuel)PiXeL16
2.9K views13 slides
Node JS (Francisco Cerdas) by
Node JS (Francisco Cerdas)Node JS (Francisco Cerdas)
Node JS (Francisco Cerdas)PiXeL16
2.1K views15 slides
Rest Introduction (Chris Jimenez) by
Rest Introduction (Chris Jimenez)Rest Introduction (Chris Jimenez)
Rest Introduction (Chris Jimenez)PiXeL16
1K views41 slides

More from PiXeL16(6)

Hooked - How to build habit forming products by PiXeL16
Hooked - How to build habit forming products Hooked - How to build habit forming products
Hooked - How to build habit forming products
PiXeL16802 views
WWDC 2016 by PiXeL16
WWDC 2016WWDC 2016
WWDC 2016
PiXeL16582 views
Resposive design (Esli David) by PiXeL16
Resposive design (Esli David)Resposive design (Esli David)
Resposive design (Esli David)
PiXeL16375 views
Estandares de Codigo (Emanuel) by PiXeL16
Estandares de Codigo (Emanuel)Estandares de Codigo (Emanuel)
Estandares de Codigo (Emanuel)
PiXeL162.9K views
Node JS (Francisco Cerdas) by PiXeL16
Node JS (Francisco Cerdas)Node JS (Francisco Cerdas)
Node JS (Francisco Cerdas)
PiXeL162.1K views
Rest Introduction (Chris Jimenez) by PiXeL16
Rest Introduction (Chris Jimenez)Rest Introduction (Chris Jimenez)
Rest Introduction (Chris Jimenez)
PiXeL161K views

Recently uploaded

ShortStory_qlora.pptx by
ShortStory_qlora.pptxShortStory_qlora.pptx
ShortStory_qlora.pptxpranathikrishna22
5 views10 slides
The Path to DevOps by
The Path to DevOpsThe Path to DevOps
The Path to DevOpsJohn Valentino
5 views6 slides
MS PowerPoint.pptx by
MS PowerPoint.pptxMS PowerPoint.pptx
MS PowerPoint.pptxLitty Sylus
5 views14 slides
Bootstrapping vs Venture Capital.pptx by
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptxZeljko Svedic
12 views17 slides
Introduction to Git Source Control by
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source ControlJohn Valentino
5 views18 slides
EV Charging App Case by
EV Charging App Case EV Charging App Case
EV Charging App Case iCoderz Solutions
8 views1 slide

Recently uploaded(20)

Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic12 views
Introduction to Git Source Control by John Valentino
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
John Valentino5 views
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy14 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok11 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable12 views
Ports-and-Adapters Architecture for Embedded HMI by Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert21 views
JioEngage_Presentation.pptx by admin125455
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptx
admin1254556 views
Generic or specific? Making sensible software design decisions by Bert Jan Schrijver
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana11 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino6 views

Mobile architecture problems and solutions.

  • 2. Mobile Architecture En el principio de los tiempos...
  • 3. MVC
  • 4. Cons ◦ Massive View Controller! ◦ Sometimes hard to test ◦ More “layers” are needed as app grows ◦ Its an “Apple thing” ◦ Decrease code clarity ◦ There are better design patterns
  • 5. What better you say? MVVM - Model View View Model --iOS MVP - Model View Presenter --Android
  • 6. MVVM ◦ View controllers are technically distinct components, they almost always go hand-in-hand together, paired ◦ When is the last time that a view could be paired with different view controllers??
  • 7. MVVM So why not formalize their connection?
  • 8. MVVM ◦ Most of the stuff in ViewController is presentation logic ◦ Things like transforming values from the model into something the view can present
  • 10. MVVM MVVM is 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.
  • 11. MVVM Why? ◦ Reduces the complexity of one’s view controllers and makes one’s presentation logic easier to test
  • 12. Some Code @interface Person : NSObject - (instancetype)initwithSalutation:(NSString *)salutation firstName:(NSString *)firstName lastName:(NSString *)lastName birthdate:(NSDate *)birthdate; @property (nonatomic, readonly) NSString *salutation; @property (nonatomic, readonly) NSString *firstName; @property (nonatomic, readonly) NSString *lastName; @property (nonatomic, readonly) NSDate *birthdate; @end
  • 13. PersonViewController.m - (void)viewDidLoad { [super viewDidLoad]; if (self.model.salutation.length > 0) { self.nameLabel.text = [NSString stringWithFormat:@"%@ %@ %@", self.model.salutation, self.model.firstName, self.model.lastName]; } else { self.nameLabel.text = [NSString stringWithFormat:@"%@ %@", self.model.firstName, self.model.lastName]; } NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEEE MMMM d, yyyy"]; self.birthdateLabel.text = [dateFormatter stringFromDate:model.birthdate]; }
  • 14. Now with MVVM, PersonViewModel.h @interface PersonViewModel : NSObject - (instancetype)initWithPerson:(Person *)person; @property (nonatomic, readonly) Person *person; @property (nonatomic, readonly) NSString *nameText; @property (nonatomic, readonly) NSString *birthdateText; @end
  • 15. PersonViewModel.m @implementation PersonViewModel - (instancetype)initWithPerson:(Person *)person { self = [super init]; if (!self) return nil; _person = person; if (person.salutation.length > 0) { _nameText = [NSString stringWithFormat:@"%@ %@ %@", self.person.salutation, self.person.firstName, self.person.lastName]; } else { _nameText = [NSString stringWithFormat:@"%@ %@", self.person.firstName, self.person.lastName]; }
  • 16. An our view controller - (void)viewDidLoad { [super viewDidLoad]; self.nameLabel.text = self.viewModel.nameText; self.birthdateLabel.text = self.viewModel.birthdateText; }
  • 18. MVP Model View Presenter Presenter is a layer that provides View with data from Model. Presenter also handles background tasks.
  • 19. Why? ◦ Keep it stupid simple ◦ Removes complexity ◦ Easy to test
  • 20. Normal View Model in Android
  • 21. On top of that ◦ View can disappear and appear at random time ◦ Do not forget about saving/restoring of Views ◦ Attach a couple of background tasks to that temporary Views
  • 23. MVP Pros ◦ Complex tasks are split into simpler tasks and are easier to solve. ◦ Smaller objects, less bugs, easier to debug. ◦ Testable.