SlideShare a Scribd company logo
1 of 19
Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved.
C2M - Mobile App
Architecture
iOS
- Suyash Gupta
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 2
Agenda
• Separation of Concerns
• MVC
• Problems with MVC
• MVP
• MVVM
• Working MVVM App
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 3
Separation of concerns
• In computer science, separation of concerns (SoC)
is a design principle for separating a computer
program into distinct sections, such that each
section addresses a separate concern.
• When concerns are well-separated, individual
sections can be reused, as well as developed and
updated independently.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 4
M-V-C (Model View Controller)
• A proven pattern for organizing your code in complex
application design, also the Apple recommended way
of programming an app.
• It’s also proven to have a second meaning in iOS
development: Massive View Controller.
• Apple hasn’t provided any real guidance on how to
solve the Massive View Controller problem
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 5
MVC
DEMO
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 6
Web MVC
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 7
Apple’s MVC
Code:
var userCell = tableView.dequeueReusableCellWithIdentifier("identifier") as UserCell
userCell.configureWithUser(user)
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 8
Problems with MVC
• Distribution— the View and the Model in fact
separated, but the View and the Controller are tightly
coupled.
• Testability — due to the bad distribution you’ll probably
only test your Model.
• Ease of use — the least amount of code among others
patterns. In addition everyone is familiar with it, thus, it’s
easily maintained even by the inexperienced
developers.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 9
Problems with MVC
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 10
MVP
DEMO
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 11
MVP
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 12
MVP- Features
• Distribution — we have the most of responsibilities
divided between the Presenter and the Model, with the
pretty dumb View
• Testability — is excellent, we can test most of the
business logic due to the dumb View.
• Easy of use — in our simple example, the amount of
code is doubled compared to the MVC, but at the same
time, idea of the MVP is very clear.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 13
MVVM
DEMO
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 14
MVVM
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 15
Some rules of MVVM
• The View has a reference to the ViewModel, but not
vice-versa.
• The ViewModel has a reference to the Model, but not
vice-versa.
• Business logic controller(VM) should have no reference
of UIKit.
• View should be only responsible for UI handling.
• View should not interact with Data Model or vice-versa.
• View Model is responsible only for processing input to
output and logic required for driving the UI as in demo
example.
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 16
MVVM-Features
• Distribution —MVVM’s View has more responsibilities
than the MVP’s View.
• Testability— the View Model knows nothing about the
View, this allows us to test it easily.
• Easy of use — its has the same amount of code as the
MVP in our example, but MVVM would be much
skinnier if you used bindings.[ReactiveCocoa]
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 17
Working MVVM App
DEMO
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 18
References
• https://academy.realm.io/posts/krzysztof-zablocki-mDevCamp-ios-
architecture-mvvm-mvc-viper/
• https://github.com/blkbrds/arch-mvvm-ios (Remove the lint pod from
podfile and build phases to make the project run)
• The references of the all the patterns are available on
Github:https://github.com/suyashgupta25/iOSPatternsSamples
Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 19

More Related Content

Similar to iOS design patterns: MVC, MVP and MVVM

Basics of Android MVP
Basics of Android MVP Basics of Android MVP
Basics of Android MVP Dinkar Kumar
 
Verification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integrationVerification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integrationRogue Wave Software
 
How to Architect and Develop Cloud Native Applications
How to Architect and Develop Cloud Native ApplicationsHow to Architect and Develop Cloud Native Applications
How to Architect and Develop Cloud Native ApplicationsSufyaan Kazi
 
Ratpack - SpringOne2GX 2015
Ratpack - SpringOne2GX 2015Ratpack - SpringOne2GX 2015
Ratpack - SpringOne2GX 2015Daniel Woods
 
Using APIs
Using APIsUsing APIs
Using APIsAkana
 
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationvue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationDivante
 
JVMCON Java in the 21st Century: are you thinking far enough ahead?
JVMCON Java in the 21st Century: are you thinking far enough ahead?JVMCON Java in the 21st Century: are you thinking far enough ahead?
JVMCON Java in the 21st Century: are you thinking far enough ahead?Steve Poole
 
The End of Security as We Know It - Shannon Lietz
The End of Security as We Know It - Shannon LietzThe End of Security as We Know It - Shannon Lietz
The End of Security as We Know It - Shannon LietzSeniorStoryteller
 
Microservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureMicroservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureKelly Goetsch
 
Exploring MVVM, MVC, MVP Patterns - CRB Tech
Exploring MVVM, MVC, MVP Patterns - CRB TechExploring MVVM, MVC, MVP Patterns - CRB Tech
Exploring MVVM, MVC, MVP Patterns - CRB TechPooja Gaikwad
 
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechVue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechDivante
 
DeveloperWeek 2020: Cloud-Native and Microservices Accelerate Process Improve...
DeveloperWeek 2020: Cloud-Native and Microservices Accelerate Process Improve...DeveloperWeek 2020: Cloud-Native and Microservices Accelerate Process Improve...
DeveloperWeek 2020: Cloud-Native and Microservices Accelerate Process Improve...Shahir Daya
 
Operations and Monitoring with Spring
Operations and Monitoring with SpringOperations and Monitoring with Spring
Operations and Monitoring with SpringEberhard Wolff
 
Navigating Your Product's Growth with Embedded Analytics
Navigating Your Product's Growth with Embedded Analytics Navigating Your Product's Growth with Embedded Analytics
Navigating Your Product's Growth with Embedded Analytics Progress
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: AndroidJitendra Kumar
 
Microservice Lifecycle Demo Presentation
Microservice Lifecycle Demo PresentationMicroservice Lifecycle Demo Presentation
Microservice Lifecycle Demo PresentationMatt McLarty
 

Similar to iOS design patterns: MVC, MVP and MVVM (20)

Basics of Android MVP
Basics of Android MVP Basics of Android MVP
Basics of Android MVP
 
C2M - App design
C2M - App designC2M - App design
C2M - App design
 
MVC 1.0 / JSR 371
MVC 1.0 / JSR 371MVC 1.0 / JSR 371
MVC 1.0 / JSR 371
 
Verification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integrationVerification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integration
 
How to Architect and Develop Cloud Native Applications
How to Architect and Develop Cloud Native ApplicationsHow to Architect and Develop Cloud Native Applications
How to Architect and Develop Cloud Native Applications
 
Ratpack - SpringOne2GX 2015
Ratpack - SpringOne2GX 2015Ratpack - SpringOne2GX 2015
Ratpack - SpringOne2GX 2015
 
Using APIs
Using APIsUsing APIs
Using APIs
 
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationvue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
 
JVMCON Java in the 21st Century: are you thinking far enough ahead?
JVMCON Java in the 21st Century: are you thinking far enough ahead?JVMCON Java in the 21st Century: are you thinking far enough ahead?
JVMCON Java in the 21st Century: are you thinking far enough ahead?
 
The End of Security as We Know It - Shannon Lietz
The End of Security as We Know It - Shannon LietzThe End of Security as We Know It - Shannon Lietz
The End of Security as We Know It - Shannon Lietz
 
Microservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureMicroservices + Oracle: A Bright Future
Microservices + Oracle: A Bright Future
 
Exploring MVVM, MVC, MVP Patterns - CRB Tech
Exploring MVVM, MVC, MVP Patterns - CRB TechExploring MVVM, MVC, MVP Patterns - CRB Tech
Exploring MVVM, MVC, MVP Patterns - CRB Tech
 
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speechVue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
Vue Storefront - Progressive Web App for Magento (1.9, 2.x) - MM18DE speech
 
DeveloperWeek 2020: Cloud-Native and Microservices Accelerate Process Improve...
DeveloperWeek 2020: Cloud-Native and Microservices Accelerate Process Improve...DeveloperWeek 2020: Cloud-Native and Microservices Accelerate Process Improve...
DeveloperWeek 2020: Cloud-Native and Microservices Accelerate Process Improve...
 
Operations and Monitoring with Spring
Operations and Monitoring with SpringOperations and Monitoring with Spring
Operations and Monitoring with Spring
 
Navigating Your Product's Growth with Embedded Analytics
Navigating Your Product's Growth with Embedded Analytics Navigating Your Product's Growth with Embedded Analytics
Navigating Your Product's Growth with Embedded Analytics
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
Microservice Lifecycle Demo Presentation
Microservice Lifecycle Demo PresentationMicroservice Lifecycle Demo Presentation
Microservice Lifecycle Demo Presentation
 
Upmc tpdev1
Upmc tpdev1Upmc tpdev1
Upmc tpdev1
 
Advanced angular
Advanced angularAdvanced angular
Advanced angular
 

Recently uploaded

Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 

Recently uploaded (7)

Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 

iOS design patterns: MVC, MVP and MVVM

  • 1. Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. C2M - Mobile App Architecture iOS - Suyash Gupta
  • 2. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 2 Agenda • Separation of Concerns • MVC • Problems with MVC • MVP • MVVM • Working MVVM App
  • 3. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 3 Separation of concerns • In computer science, separation of concerns (SoC) is a design principle for separating a computer program into distinct sections, such that each section addresses a separate concern. • When concerns are well-separated, individual sections can be reused, as well as developed and updated independently.
  • 4. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 4 M-V-C (Model View Controller) • A proven pattern for organizing your code in complex application design, also the Apple recommended way of programming an app. • It’s also proven to have a second meaning in iOS development: Massive View Controller. • Apple hasn’t provided any real guidance on how to solve the Massive View Controller problem
  • 5. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 5 MVC DEMO
  • 6. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 6 Web MVC
  • 7. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 7 Apple’s MVC Code: var userCell = tableView.dequeueReusableCellWithIdentifier("identifier") as UserCell userCell.configureWithUser(user)
  • 8. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 8 Problems with MVC • Distribution— the View and the Model in fact separated, but the View and the Controller are tightly coupled. • Testability — due to the bad distribution you’ll probably only test your Model. • Ease of use — the least amount of code among others patterns. In addition everyone is familiar with it, thus, it’s easily maintained even by the inexperienced developers.
  • 9. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 9 Problems with MVC
  • 10. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 10 MVP DEMO
  • 11. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 11 MVP
  • 12. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 12 MVP- Features • Distribution — we have the most of responsibilities divided between the Presenter and the Model, with the pretty dumb View • Testability — is excellent, we can test most of the business logic due to the dumb View. • Easy of use — in our simple example, the amount of code is doubled compared to the MVC, but at the same time, idea of the MVP is very clear.
  • 13. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 13 MVVM DEMO
  • 14. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 14 MVVM
  • 15. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 15 Some rules of MVVM • The View has a reference to the ViewModel, but not vice-versa. • The ViewModel has a reference to the Model, but not vice-versa. • Business logic controller(VM) should have no reference of UIKit. • View should be only responsible for UI handling. • View should not interact with Data Model or vice-versa. • View Model is responsible only for processing input to output and logic required for driving the UI as in demo example.
  • 16. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 16 MVVM-Features • Distribution —MVVM’s View has more responsibilities than the MVP’s View. • Testability— the View Model knows nothing about the View, this allows us to test it easily. • Easy of use — its has the same amount of code as the MVP in our example, but MVVM would be much skinnier if you used bindings.[ReactiveCocoa]
  • 17. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 17 Working MVVM App DEMO
  • 18. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 18 References • https://academy.realm.io/posts/krzysztof-zablocki-mDevCamp-ios- architecture-mvvm-mvc-viper/ • https://github.com/blkbrds/arch-mvvm-ios (Remove the lint pod from podfile and build phases to make the project run) • The references of the all the patterns are available on Github:https://github.com/suyashgupta25/iOSPatternsSamples
  • 19. Copyright © 2016 Talentica Software (I) Pvt Ltd. All rights reserved.Copyright ©2016 Talentica Software (I) Pvt Ltd. All rights reserved. 19