SlideShare a Scribd company logo
1 of 34
Download to read offline
Modelsin iOS programming
describing MVVM as MCV’s natural evolution step
Andrei Popa
Agenda1) Separation of Concerns
2) MVC
3) Problems with MVC
4) MVVM - describing MVVM as MCV’s natural evolution step
5) ReactiveCocoa as binding solution in iOS
6) Android correspondence, MVP
Andrei Popa
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.
Of special value is the ability to later improve or modify one section of code
without having to know the details of other sections, and without having to make
corresponding changes to those sections.
separation of concerns
Separation of concerns is an important design principle in many other areas
as well, such as urban planning, architecture and information design.
The goal is to more effectively understand, design, and manage complex
interdependent systems, so that functions can be reused, optimized
independently of other functions, and insulated from the potential failure of
other functions.
separation of concerns
MVC or MVP can separate content from presentation
MVVM can separate data gathering / logic / transforming from the
complexities of a view controller.
separation of concerns
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
• defines the roles objects play in the application
• 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
M-V-C
• God object
• Responsible for the actual UI (whether that means
UIView code, storyboards, or xibs), any view specific
logic, and reaction to user input
• This includes a lot of the responsibilities handled by
the UIViewController in iOS, not just UIView code and
files
Massive View Controller
M-V-VM
• MVVM stands for Model View View-Model, and it’s here to
help us create more manageable, better designed code.
• The testability and separation of concerns are some of the
good things that come out of this particular pattern.
• MVVM is a pattern to separate the concern of
presentation from domain.
• Developed by Microsoft's for WPF and Silverlight architecture, and
currently the pattern of choice for Windows Phone Development
M-V-VM
M-V-VM
• This leaves the view (controller) with a more clearly defined task of
presenting the data supplied by the view-model.
• The view-model exposes the minimum information necessary to our
view controller, and the view controller really doesn’t care how the
view-model got that information.
M-V-VM
M-V-VM
• View independent representation of business entities
• Represents the data layer
• Responsible for fetching / storing the data
• CoreData / Realm / Parse / …
• JSON
• Encryption
M-V-VM (Model)
M-V-VM (viewModel)
• In some of the WWDC videos this year, viewModels were actually
spotted in the sample code apple engineers had on screen.
• One of its responsibilities is that of a static model representing the
data necessary for the view to display itself; but it’s also
responsible for gathering, interpreting, and transforming that data.
• Kicking off network or database requests
• Determining when information should be hidden or shown
• Localization
• Date and number formatting
• It is NOT acting directly on the view controller in any form or
notifying it directly of changes
M-V-VM (viewModel)
• MVVM and MVC share a common weakness: neither
defines where the network logic of an app should go.
• Add the networking logic in the viewModel
• View models are (mostly) platform-agnostic.
• It applies logic and massages the data from the model into
presentation data for the view (controller).
• It exposes (usually via properties) only the information the
view controller needs to know about to do its job of
displaying the view (ideally you are not exposing your data-
model objects).
• It is NOT acting directly on the view controller in any form or
notifying it directly of changes
M-V-VM (viewModel)
• The view controller’s only concerns are:
• configuring and managing the various views with data from the
view-model
• letting the view-model know when relevant user input occurs
that needs to change data upstream
• Layout / Animations / Device rotations / View transitions
• Inject viewModel to viewController during init
• The view controller doesn’t need to know about anything
else
M-V-VM (view / UIViewController)
• ViewModel becomes extremely unit testable. If you have
methods that should generate the same output every time
they are supplied the same input (pure functions), that fits
extremely well into the world of unit tests.
• We now have our data gathering / logic / transforming
extracted away from the complexities of a view controller.
• When the view model needs to communicate something
to the view, it does so through a system of data bindings
M-V-VM (Advantages)
Data bindingsWhat about when data on the view-model changes?
Data bindings
Data bindings
A signal takes all those async methods for controlling the
flow of information through your app (delegates, callback
blocks, notifications, KVO, target/action event observers,
etc) and unifies them under one interface.
Stateless binding using
ReactiveCocoa
In some cases you can eliminate even more state on
your view-model by exposing RACSignals instead of
properties like strings and images.
Then your view controller wouldn’t have to create its own
with RACObserve, and could just leverage those signals
straightaway.
ReactiveCocoa
• By modeling changes as signals, the view model can
communicate to the view without actually needing to know
that it exists
• similarly for model → view model communication
• This decoupling is why view models can be tested without
a view in place — the test simply needs to connect to the
VM's signals and verify that the behavior is correct.
M-V-VM
• Framework inspired by Functional Reactive
Programming
• Fancy bindings
• Event streams unify all of Cocoa’s common patterns for
asynchrony and event handling
• Mature, production-ready framework
• Wide-adoption by top-class developers
ReactiveCocoa
• The Model-View-Presenter-pattern (MVP) has been the
dominating trend lately when it comes the UI-layer
architecture of Android applications.
• Data Binding, as announced on Google I/O 2015
changes everything.
• https://developer.android.com/tools/data-binding/
guide.html
• https://github.com/ReactiveX/RxAndroid
MVVM on Android
• Data Binding framework will take over the main
responsibilities of the Presenter (“acting upon the
model and the view”), while the remainder is left to the
enhanced Model – the ViewModel (“retrieving data from
repositories and formatting”).
• The ViewModel is a standard Java class whose sole
responsibility is to represent the data behind a single
View. It can merge data from multiple sources (Models)
and prepare that data for presentation.
MVVM on Android
Thank you!Q&A

More Related Content

What's hot

MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)Yaroslav Voloshyn
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnetrainynovember12
 
Introduction to WPF and MVVM
Introduction to WPF and MVVMIntroduction to WPF and MVVM
Introduction to WPF and MVVMSirar Salih
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009Jonas Follesø
 
Ui design patterns
Ui design patternsUi design patterns
Ui design patternsJorge Ortiz
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPFS V
 
MVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,MobileMVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,Mobilenaral
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Jennie Gajjar
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMDong-Ho Lee
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModelDareen Alhiyari
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)M Ahsan Khan
 
Struts & hibernate ppt
Struts & hibernate pptStruts & hibernate ppt
Struts & hibernate pptPankaj Patel
 
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fairTech_MX
 

What's hot (20)

Slide Presentation of MVP Pattern Concept
Slide Presentation of MVP Pattern ConceptSlide Presentation of MVP Pattern Concept
Slide Presentation of MVP Pattern Concept
 
MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnet
 
Introduction to WPF and MVVM
Introduction to WPF and MVVMIntroduction to WPF and MVVM
Introduction to WPF and MVVM
 
PAC
PACPAC
PAC
 
MVC
MVCMVC
MVC
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009
 
Ui design patterns
Ui design patternsUi design patterns
Ui design patterns
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPF
 
MVC
MVCMVC
MVC
 
MVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,MobileMVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,Mobile
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
 
Mvc, mvp, mvvm...
Mvc, mvp, mvvm...Mvc, mvp, mvvm...
Mvc, mvp, mvvm...
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
MVC
MVCMVC
MVC
 
Struts & hibernate ppt
Struts & hibernate pptStruts & hibernate ppt
Struts & hibernate ppt
 
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fair
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
 

Similar to Models used in iOS programming, with a focus on MVVM

Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesQamar Abbas
 
Android DesignArchitectures.pptx
Android DesignArchitectures.pptxAndroid DesignArchitectures.pptx
Android DesignArchitectures.pptxSafnaSaff1
 
Choosing the Right HTML5 Framework to Build your Mobile Web Application White...
Choosing the Right HTML5 Framework to Build your Mobile Web Application White...Choosing the Right HTML5 Framework to Build your Mobile Web Application White...
Choosing the Right HTML5 Framework to Build your Mobile Web Application White...RapidValue
 
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
Mvc vs mvp vs mvvm  a guide on architecture presentation patternsMvc vs mvp vs mvvm  a guide on architecture presentation patterns
Mvc vs mvp vs mvvm a guide on architecture presentation patternsConcetto Labs
 
SUE AGILE MVVM (English)
SUE AGILE MVVM (English)SUE AGILE MVVM (English)
SUE AGILE MVVM (English)Sabino Labarile
 
Using mvvm inside mvc in domain driven design
Using mvvm inside mvc in domain driven designUsing mvvm inside mvc in domain driven design
Using mvvm inside mvc in domain driven designyashar Aliabasi
 
Web engineering - MVC
Web engineering - MVCWeb engineering - MVC
Web engineering - MVCNosheen Qamar
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patternsalkuzaee
 
Task 2 - Educational Article – Model View Controller (MVC)
Task 2 - Educational Article – Model View Controller (MVC)Task 2 - Educational Article – Model View Controller (MVC)
Task 2 - Educational Article – Model View Controller (MVC)Shubham Goenka
 
Code Camp 06 Model View Presenter Architecture
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecturebitburner93
 
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & PatternsInocentshuja Ahmad
 
реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработкеProvectus
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: AndroidJitendra Kumar
 
Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patternseleksdev
 

Similar to Models used in iOS programming, with a focus on MVVM (20)

MVC.pptx
MVC.pptxMVC.pptx
MVC.pptx
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Android DesignArchitectures.pptx
Android DesignArchitectures.pptxAndroid DesignArchitectures.pptx
Android DesignArchitectures.pptx
 
Choosing the Right HTML5 Framework to Build your Mobile Web Application White...
Choosing the Right HTML5 Framework to Build your Mobile Web Application White...Choosing the Right HTML5 Framework to Build your Mobile Web Application White...
Choosing the Right HTML5 Framework to Build your Mobile Web Application White...
 
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
Mvc vs mvp vs mvvm  a guide on architecture presentation patternsMvc vs mvp vs mvvm  a guide on architecture presentation patterns
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
 
Mvvm
MvvmMvvm
Mvvm
 
SUE AGILE MVVM (English)
SUE AGILE MVVM (English)SUE AGILE MVVM (English)
SUE AGILE MVVM (English)
 
IntroductionToMVC
IntroductionToMVCIntroductionToMVC
IntroductionToMVC
 
Adopting MVVM
Adopting MVVMAdopting MVVM
Adopting MVVM
 
Using mvvm inside mvc in domain driven design
Using mvvm inside mvc in domain driven designUsing mvvm inside mvc in domain driven design
Using mvvm inside mvc in domain driven design
 
Web engineering - MVC
Web engineering - MVCWeb engineering - MVC
Web engineering - MVC
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Task 2 - Educational Article – Model View Controller (MVC)
Task 2 - Educational Article – Model View Controller (MVC)Task 2 - Educational Article – Model View Controller (MVC)
Task 2 - Educational Article – Model View Controller (MVC)
 
Code Camp 06 Model View Presenter Architecture
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecture
 
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & Patterns
 
реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработке
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patterns
 
Mvc Architecture in a web based application
Mvc Architecture in a web based applicationMvc Architecture in a web based application
Mvc Architecture in a web based application
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Models used in iOS programming, with a focus on MVVM

  • 1. Modelsin iOS programming describing MVVM as MCV’s natural evolution step Andrei Popa
  • 2. Agenda1) Separation of Concerns 2) MVC 3) Problems with MVC 4) MVVM - describing MVVM as MCV’s natural evolution step 5) ReactiveCocoa as binding solution in iOS 6) Android correspondence, MVP Andrei Popa
  • 3.
  • 4. 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. Of special value is the ability to later improve or modify one section of code without having to know the details of other sections, and without having to make corresponding changes to those sections. separation of concerns
  • 5. Separation of concerns is an important design principle in many other areas as well, such as urban planning, architecture and information design. The goal is to more effectively understand, design, and manage complex interdependent systems, so that functions can be reused, optimized independently of other functions, and insulated from the potential failure of other functions. separation of concerns
  • 6. MVC or MVP can separate content from presentation MVVM can separate data gathering / logic / transforming from the complexities of a view controller. separation of concerns
  • 7. 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 • defines the roles objects play in the application • 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
  • 9.
  • 10. • God object • Responsible for the actual UI (whether that means UIView code, storyboards, or xibs), any view specific logic, and reaction to user input • This includes a lot of the responsibilities handled by the UIViewController in iOS, not just UIView code and files Massive View Controller
  • 11.
  • 12. M-V-VM • MVVM stands for Model View View-Model, and it’s here to help us create more manageable, better designed code. • The testability and separation of concerns are some of the good things that come out of this particular pattern. • MVVM is a pattern to separate the concern of presentation from domain. • Developed by Microsoft's for WPF and Silverlight architecture, and currently the pattern of choice for Windows Phone Development
  • 15. • This leaves the view (controller) with a more clearly defined task of presenting the data supplied by the view-model. • The view-model exposes the minimum information necessary to our view controller, and the view controller really doesn’t care how the view-model got that information. M-V-VM
  • 17. • View independent representation of business entities • Represents the data layer • Responsible for fetching / storing the data • CoreData / Realm / Parse / … • JSON • Encryption M-V-VM (Model)
  • 18. M-V-VM (viewModel) • In some of the WWDC videos this year, viewModels were actually spotted in the sample code apple engineers had on screen. • One of its responsibilities is that of a static model representing the data necessary for the view to display itself; but it’s also responsible for gathering, interpreting, and transforming that data. • Kicking off network or database requests • Determining when information should be hidden or shown • Localization • Date and number formatting • It is NOT acting directly on the view controller in any form or notifying it directly of changes
  • 19. M-V-VM (viewModel) • MVVM and MVC share a common weakness: neither defines where the network logic of an app should go. • Add the networking logic in the viewModel
  • 20. • View models are (mostly) platform-agnostic. • It applies logic and massages the data from the model into presentation data for the view (controller). • It exposes (usually via properties) only the information the view controller needs to know about to do its job of displaying the view (ideally you are not exposing your data- model objects). • It is NOT acting directly on the view controller in any form or notifying it directly of changes M-V-VM (viewModel)
  • 21. • The view controller’s only concerns are: • configuring and managing the various views with data from the view-model • letting the view-model know when relevant user input occurs that needs to change data upstream • Layout / Animations / Device rotations / View transitions • Inject viewModel to viewController during init • The view controller doesn’t need to know about anything else M-V-VM (view / UIViewController)
  • 22. • ViewModel becomes extremely unit testable. If you have methods that should generate the same output every time they are supplied the same input (pure functions), that fits extremely well into the world of unit tests. • We now have our data gathering / logic / transforming extracted away from the complexities of a view controller. • When the view model needs to communicate something to the view, it does so through a system of data bindings M-V-VM (Advantages)
  • 23. Data bindingsWhat about when data on the view-model changes?
  • 26. A signal takes all those async methods for controlling the flow of information through your app (delegates, callback blocks, notifications, KVO, target/action event observers, etc) and unifies them under one interface. Stateless binding using ReactiveCocoa
  • 27. In some cases you can eliminate even more state on your view-model by exposing RACSignals instead of properties like strings and images. Then your view controller wouldn’t have to create its own with RACObserve, and could just leverage those signals straightaway. ReactiveCocoa
  • 28. • By modeling changes as signals, the view model can communicate to the view without actually needing to know that it exists • similarly for model → view model communication • This decoupling is why view models can be tested without a view in place — the test simply needs to connect to the VM's signals and verify that the behavior is correct. M-V-VM
  • 29. • Framework inspired by Functional Reactive Programming • Fancy bindings • Event streams unify all of Cocoa’s common patterns for asynchrony and event handling • Mature, production-ready framework • Wide-adoption by top-class developers ReactiveCocoa
  • 30. • The Model-View-Presenter-pattern (MVP) has been the dominating trend lately when it comes the UI-layer architecture of Android applications. • Data Binding, as announced on Google I/O 2015 changes everything. • https://developer.android.com/tools/data-binding/ guide.html • https://github.com/ReactiveX/RxAndroid MVVM on Android
  • 31. • Data Binding framework will take over the main responsibilities of the Presenter (“acting upon the model and the view”), while the remainder is left to the enhanced Model – the ViewModel (“retrieving data from repositories and formatting”). • The ViewModel is a standard Java class whose sole responsibility is to represent the data behind a single View. It can merge data from multiple sources (Models) and prepare that data for presentation. MVVM on Android
  • 32.
  • 33.