SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sara Torkey
 

La actualidad más candente (20)

«Управление логикой переходов между экранами приложения с помощью координатор...
«Управление логикой переходов между экранами приложения с помощью координатор...«Управление логикой переходов между экранами приложения с помощью координатор...
«Управление логикой переходов между экранами приложения с помощью координатор...
 
iOS Architectures
iOS ArchitecturesiOS Architectures
iOS Architectures
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
Mvc, mvp, mvvm...
Mvc, mvp, mvvm...Mvc, mvp, mvvm...
Mvc, mvp, mvvm...
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPF
 
Clean code: SOLID (iOS)
Clean code: SOLID (iOS)Clean code: SOLID (iOS)
Clean code: SOLID (iOS)
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Angular components
Angular componentsAngular components
Angular components
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
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 with DataBinding on android
MVVM with DataBinding on androidMVVM with DataBinding on android
MVVM with DataBinding on android
 
iOS viper presentation
iOS viper presentationiOS viper presentation
iOS viper presentation
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Android MVVM
Android MVVMAndroid MVVM
Android MVVM
 

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

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
Tech_MX
 
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
MasterCode.vn
 
Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01Mvc 130330091359-phpapp01
Mvc 130330091359-phpapp01
Jennie Gajjar
 

Similar a 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
 

Último

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Último (20)

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 

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

Notas del editor

  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