SlideShare a Scribd company logo
1 of 12
MVx patterns in iOS
Back to 1970s - MVC
It was at the beginning
Apple's result
● Controller changes Model and update View.
Controller can have many views
● View represents information from the Model
● Model is a data/logic/rules
MVC - conclusion
● Drawbacks
○ The View and the Model in fact are separated, but the View and the
Controller are tightly coupled
○ Difficult to test and maintain
○ Cause a massive ViewController
● Benefits
○ Cocoa MVC is the best architectural pattern in terms of the speed
of the development
○ Everyone is familiar with this approach
MVP
● Passive view
● Supervising controller
MVP - passive view
● The Model is the data
● The View is a passive
interface that displays
data and routes events
to the Presenter
● The Presenter retrieves
data from the Model,
and formats it for display
in the View. UIKit
independent.
MVP - sequence diagram
MVP - supervising controller
The main difference from
a PassiveView MVP is
Data Binding
This version of pattern is
less popular because of
tight coupling between the
View and the Model
MVP - conclusion
● Drawbacks
○ Time consuming
● Benefits
○ The responsibilities are divided between components
○ Reusable components
○ Testability is excellent, we can test most of the business logic due
to the dumb View
MVVM
● The Model is the data
● The View represents the
data from ViewModel
● ViewModel knows about
the Model and
fetch/create/update a data
and notify the View about
changes. UIKit
independent.
MVVM - sequence diagram
MVVM - conclusion
● Drawbacks
○ Data binding between the View and the ViewModel can be
compicated
● Benefits
○ The ViewModel and the Model can be easily tested because are
independent of UIKit
○ The responsibilities divided between components
Code examples
You can find Xcode project with examples MVC, MVP and
MVVM on GitHub page:
https://github.com/voloshynslavik/MVx-Patterns-In-Swift

More Related Content

What's hot

MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModelDareen Alhiyari
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureBadoo
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in JavaIonut Bilica
 
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
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Svetlin Nakov
 
Clean architecture
Clean architectureClean architecture
Clean architecture.NET Crowd
 
소프트웨어 아키텍처
소프트웨어 아키텍처소프트웨어 아키텍처
소프트웨어 아키텍처영기 김
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPFS V
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architectureravindraquicsolv
 
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #1, NDC2017
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #1, NDC2017이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #1, NDC2017
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #1, NDC2017devCAT Studio, NEXON
 
Geecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesGeecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesBruno Bossola
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC StructureDipika Wadhvani
 

What's hot (20)

MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
 
Android MVVM
Android MVVMAndroid MVVM
Android MVVM
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
소프트웨어 아키텍처
소프트웨어 아키텍처소프트웨어 아키텍처
소프트웨어 아키텍처
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPF
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #1, NDC2017
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #1, NDC2017이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #1, NDC2017
이승재, 강성훈, 내가 만든 언어의 개발환경을 Visual Studio Code로 빠르고 쉽게 구축하기 #1, NDC2017
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Geecon09: SOLID Design Principles
Geecon09: SOLID Design PrinciplesGeecon09: SOLID Design Principles
Geecon09: SOLID Design Principles
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 

Similar to MVx patterns in iOS (MVC, MVP, MVVM)

MVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive appsMVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive appsKotiTenali
 
реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработкеProvectus
 
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentationInova LLC
 
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
 
Web engineering - MVC
Web engineering - MVCWeb engineering - MVC
Web engineering - MVCNosheen Qamar
 
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & PatternsInocentshuja Ahmad
 
Session 5 : mvc - Giáo trình Bách Khoa Aptech
Session 5 : mvc  - Giáo trình Bách Khoa AptechSession 5 : mvc  - Giáo trình Bách Khoa Aptech
Session 5 : mvc - Giáo trình Bách Khoa AptechMasterCode.vn
 
Ui design patterns
Ui design patternsUi design patterns
Ui design patternsJorge Ortiz
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesQamar Abbas
 
Interaction-Oriented Architecture.pptx
Interaction-Oriented Architecture.pptxInteraction-Oriented Architecture.pptx
Interaction-Oriented Architecture.pptxGodwin Monserate
 
Model View Controller ext4
Model View Controller  ext4Model View Controller  ext4
Model View Controller ext4Pankaj Avhad
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Jennie Gajjar
 
software architecture
software architecturesoftware architecture
software architecturearnav gupta
 

Similar to MVx patterns in iOS (MVC, MVP, MVVM) (20)

MVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive appsMVC architecture in software programming for interactive apps
MVC architecture in software programming for interactive apps
 
реалии использования Mv в i os разработке
реалии использования Mv в i os разработкереалии использования Mv в i os разработке
реалии использования Mv в i os разработке
 
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentation
 
Knockout js
Knockout jsKnockout js
Knockout js
 
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
 
Ios models
Ios modelsIos models
Ios models
 
Web engineering - MVC
Web engineering - MVCWeb engineering - MVC
Web engineering - MVC
 
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & Patterns
 
Model View Controller
Model View ControllerModel View Controller
Model View Controller
 
Session 5 : mvc - Giáo trình Bách Khoa Aptech
Session 5 : mvc  - Giáo trình Bách Khoa AptechSession 5 : mvc  - Giáo trình Bách Khoa Aptech
Session 5 : mvc - Giáo trình Bách Khoa Aptech
 
MVVM and Prism
MVVM and PrismMVVM and Prism
MVVM and Prism
 
Ui design patterns
Ui design patternsUi design patterns
Ui design patterns
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
MVC
MVCMVC
MVC
 
Interaction-Oriented Architecture.pptx
Interaction-Oriented Architecture.pptxInteraction-Oriented Architecture.pptx
Interaction-Oriented Architecture.pptx
 
MVP Clean Architecture
MVP Clean  Architecture MVP Clean  Architecture
MVP Clean Architecture
 
Model View Controller ext4
Model View Controller  ext4Model View Controller  ext4
Model View Controller ext4
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
 
software architecture
software architecturesoftware architecture
software architecture
 

Recently uploaded

Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 

Recently uploaded (20)

Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 

MVx patterns in iOS (MVC, MVP, MVVM)

  • 2. Back to 1970s - MVC It was at the beginning Apple's result ● Controller changes Model and update View. Controller can have many views ● View represents information from the Model ● Model is a data/logic/rules
  • 3. MVC - conclusion ● Drawbacks ○ The View and the Model in fact are separated, but the View and the Controller are tightly coupled ○ Difficult to test and maintain ○ Cause a massive ViewController ● Benefits ○ Cocoa MVC is the best architectural pattern in terms of the speed of the development ○ Everyone is familiar with this approach
  • 4. MVP ● Passive view ● Supervising controller
  • 5. MVP - passive view ● The Model is the data ● The View is a passive interface that displays data and routes events to the Presenter ● The Presenter retrieves data from the Model, and formats it for display in the View. UIKit independent.
  • 6. MVP - sequence diagram
  • 7. MVP - supervising controller The main difference from a PassiveView MVP is Data Binding This version of pattern is less popular because of tight coupling between the View and the Model
  • 8. MVP - conclusion ● Drawbacks ○ Time consuming ● Benefits ○ The responsibilities are divided between components ○ Reusable components ○ Testability is excellent, we can test most of the business logic due to the dumb View
  • 9. MVVM ● The Model is the data ● The View represents the data from ViewModel ● ViewModel knows about the Model and fetch/create/update a data and notify the View about changes. UIKit independent.
  • 10. MVVM - sequence diagram
  • 11. MVVM - conclusion ● Drawbacks ○ Data binding between the View and the ViewModel can be compicated ● Benefits ○ The ViewModel and the Model can be easily tested because are independent of UIKit ○ The responsibilities divided between components
  • 12. Code examples You can find Xcode project with examples MVC, MVP and MVVM on GitHub page: https://github.com/voloshynslavik/MVx-Patterns-In-Swift

Editor's Notes

  1. Today we will talk about three most most popular architecture patterns in iOS MVC MVP and MVVM. First of all we will look at structure and then will check how does it look in code. I wrote simple one screen application that downloads photos and displays them in UICollectionView.
  2. So, let's start from the oldest one - MVC Here we have 3 main components Controller View and Model In this case, the View is stateless. It is simply rendered by the Controller once the Model is changed. What did Apple? They combined View and Controller into one entity that calls viewcontoller let's see how does it look in example
  3. Classical MVC is usuful but not in iOS, because it causes big amount of problems. To be honest I'm not sure that we can call this MVC that provides us Apple. This approach is the main reason why we have code that can't be covered by tests and a MassiveViewController. It's difficult to belive in it, but there are even benefits. At least everyone knows how to write a code in this style and this pattern is the best one if you need quickly check something, for example proof of concept or prototype.
  4. This pattern is more powerful than the previous one. MPV has 2 different modifications: first Passive view and second supervising controller. Let's start from Passive view and then check the differences between them
  5. The Model is the same as in MVC but Presenter and a View are completely different The presenter is the cental part that knows about Data and View. Between presenter and model there is typical connection. Presenter has a link on the model and model notifies about changes via calback or delegates But There is an interesting connection between view and presenter. Actually this part between view-presenter contection was the most confusing for me. They have a link on each other. It means thas one of them should be declared as a weak reference.
  6. Here you can see how it works User, for example, press button and View cathes this event Then redirect the event to presenter. Presenter handles it somehow, do something with model and updates the View at the end
  7. As you can see this version of MVP pattern looks the same as the previous one. But here we see data bindling with a model.
  8. This pattern is quite complex to understand at the beginning and probably it's the most time consuming pattern from an MV* generation. But in the end you will get the flexible structure that can be easy covered by tests. The reusability is marvellous. You can reuse everything. Let's imagine that the same screen with CollectionView that represents list of images from Instagram, then we need to simply add new Presenter that downloads photos from another source. And vise-versa if we want to add new new screen with table view instead of collection view, or just show single image. You need just change a view, but presenter can be the same.
  9. This pattern is more familiar us then previous 2. The view has a reference on view model, and viiew model has a reference on the model. One important think is that viewmodel is uikit independent. It means that we can't use classes from UIKIt framework.
  10. The quality of image is not the best, but I hope that you see what is there so, how does it work in general? for example user clicks on the button, view catch this event and asks ViewModel to handle it. then view model update model and notifies the View about result
  11. And conclusion If talk about bad side of viewmodel it can be data binding. It is easy to track changes in viewmodel if you have only one object, but if track for example 5 and everyone has own callback or delegate it's became messy but viewmodel pattern is good in that sense that responsibilities are devided between components and these components can be easily tested