SlideShare a Scribd company logo
1 of 52
Download to read offline
from MVC to VIPER 
Krzysztof Profic 
@kprofic
Legacy codebase 
Better codebase
Pragmatic approach 
what hurts my eyes?
Pragmatic approach 
what hurts my eyes? 
UIViewController
Massive 
UIViewController
4 Steps 
• MVC on diet 
• MVVM 
• Intentions 
• VIPER
4 Steps 
• MVC on diet 
• MVVM 
• Intentions 
• VIPER
MVC on diet 
Massive View Controller 
Light View Controller
Reducing 
Massive ViewController 
• extract datasource 
• move domain logic into the model 
• move view code into the view layer 
objc.io #1
Reducing 
Massive ViewController 
• extract datasource 
• move domain logic into the model 
• move view code into the view layer 
objc.io #1
Reducing 
Massive ViewController 
• extract datasource 
• move domain logic into the model 
• move view code into the view layer 
objc.io #1
Reducing 
Massive ViewController 
• Separation of concerns 
• Single responsibility principle 
objc.io #1
Reanimate your MVC 
reduce MVC principles violation 
put ViewController on a diet
What is the Rule?
“Keep the code where 
it belongs”
Layer
Controllers 
Use Cases 
Entities 
Presenters 
Gateways 
UI 
DB 
External 
Interfaces 
Devices 
The Clean Architecture 
Enterprise Business Rules 
Application Business Rules 
Interface Adapters 
Frameworks & Drivers 
Web 
Controller 
Use Case 
Interactor 
Presenter 
Use Case 
Output Port 
Use Case 
Input Port 
Flow of control 
<I> 
<I> 
http://blog.8thlight.com
separation of concerns = dividing software into … 
Layers
“Keep the code on 
the right layer”
The Dependency Rule
Controllers 
Use Cases 
Entities 
Presenters 
Gateways 
UI 
DB 
External 
Interfaces 
Devices 
The Clean Architecture 
Enterprise Business Rules 
Application Business Rules 
Interface Adapters 
Frameworks & Drivers 
Web 
Controller 
Use Case 
Interactor 
Presenter 
Use Case 
Output Port 
Use Case 
Input Port 
Flow of control 
<I> 
<I> 
http://blog.8thlight.com
MVC variation
MVC variation
MVVM
4 Steps 
• MVC on diet 
• MVVM 
• Intentions 
• VIPER
Let’s talk code
- (void)viewDidLoad { 
[super viewDidLoad]; 
if (self.model.salutation.length > 0) { 
self.nameLabel.text = [NSString stringWithFormat:@"%@ %@ %@“, 
self.model.salutation, 
self.model.firstName, 
self.model.lastName]; 
} else { 
self.nameLabel.text = [NSString stringWithFormat:@"%@ %@“, 
self.model.firstName, 
self.model.lastName]; 
} 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"EEEE MMMM d, yyyy"]; 
self.birthdateLabel.text = [dateFormatter 
stringFromDate:model.birthdate]; 
} 
PersonViewController.m
@implementation PersonViewModel 
- (instancetype)initWithPerson:(Person *)person { 
self = [super init]; 
if (!self) return nil; 
_person = person; 
if (person.salutation.length > 0) { 
_nameText = [NSString stringWithFormat:@"%@ %@ %@“, 
self.person.salutation, 
self.person.firstName, self.person.lastName]; 
} else { 
_nameText = [NSString stringWithFormat:@"%@ %@", 
self.person.firstName, 
self.person.lastName]; 
} 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"EEEE MMMM d, yyyy"]; 
_birthdateText = [dateFormatter 
stringFromDate:person.birthdate]; 
return self; 
} 
@end PersonViewModel.m
- (void)viewDidLoad { 
[super viewDidLoad]; 
self.nameLabel.text = self.viewModel.nameText; 
self.birthdateLabel.text = self.viewModel.birthdateText; 
} 
PersonViewController.m
4 Steps 
• MVC on diet 
• MVVM 
• Intentions 
• VIPER
Motivation 
• ViewController implements only viewWill* viewDid*
• encapsulate small pieces of business logic 
• use case approach (form validation, login user) 
• hookable via & 
• reusable 
Intentions 
Architecture is about Intent “Uncle Bob” 
IBOutlet IBAction
@interface ViewController () 
@property (strong) IBOutlet ModelContainer* modelContainer; 
@end 
@implementation ViewController 
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
PersonViewModel * pvm = [[PersonViewModel alloc] 
initWithModel:self.person]; 
self.modelContainer.viewModel = pvm; 
} 
@end 
ViewController.m
Observing ViewModel
@interface ObserveIntention () 
@property (strong, nonatomic) IBOutlet id sourceObject; 
@property (strong, nonatomic) IBOutlet id target; 
@property (copy, nonatomic) IBOutlet NSString *sourceKeyPath; 
@property (copy, nonatomic) IBOutlet NSString *targetKeyPath; 
@end
@implementation ObserveIntention 
- (void)awakeFromNib { 
[super awakeFromNib]; 
[self updateValue]; 
[self.sourceObject addObserver:self 
forKeyPath:self.sourceKeyPath options:0 context:nil]; 
} 
- (void)updateValue { 
id value = [self.sourceObject valueForKeyPath: 
self.sourceKeyPath]; 
if (self.targetKeyPath) { 
[self.target setValue:value forKeyPath:self.targetKeyPath]; 
} 
} 
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)obj 
change:(NSDictionary *)change context:(void *)context { 
if ([keyPath isEqualToString:self.sourceKeyPath]) { 
[self updateValue]; 
} 
} 
@end
Behaviours 
UIControl 
objc.io #13
Login
User Story #90.10 - Login 
• A. When I as a user open the app the first time I 
enter the “main login” page, where I need to login 
with my username (email address) and password. 
• B. When I tap the “login button” while online and no 
errors occur I’m moved to initial page with users 
profile.
User Story #90.10 - Login 
• A. When I as a user open the app the first time I 
enter the “main login” page, where I need to login 
with my username (email address) and password. 
• B. When I tap the “login button” while online and 
no errors occur I’m moved to initial page with users 
profile.
@interface LoginIntention() 
@property (strong) IBOutlet UITextField * usernameTextField; 
@property (strong) IBOutlet UITextField * passwordTextField; 
@property (strong, nonatomic) IBOutlet UILabel * statusLabel; 
@end 
@implementation LoginIntention 
- (IBAction)login:(id)sender { 
self.statusLabel.text = @"connecting..."; 
[self sendActionsForControlEvents:UIControlEventValueChanged]; 
self.statusLabel.text = [NSString 
stringWithFormat:@"Authenticating %@“, 
self.usernameTextField.text]; 
[self sendActionsForControlEvents:UIControlEventValueChanged]; 
self.statusLabel.text = @"done"; 
[self sendActionsForControlEvents:UIControlEventValueChanged]; 
} 
@end 
LoginIntention.m
@implementation LoginViewController 
- (IBAction)loginIntentionStateChanged:(LoginIntention *)sender { 
if ([sender.statusLabel.text isEqualToString:@"done"]){ 
[self.presentingViewController 
dismissViewControllerAnimated:YES completion:nil]; 
} 
} 
@end 
LoginViewController.m
4 Steps 
• MVC on diet 
• MVVM 
• Intentions 
• VIPER
If you want more, checkout 
VIPER 
• View 
• Interactor 
• Presenter 
• Entity 
• Routing
Summary: 
MVC on diet 
MVVM 
Intentions / Behaviours 
VIPER
Thank you! 
Krzysztof Profic 
@kprofic
• http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean- 
architecture.html 
• http://www.scottlogic.com/blog/2014/05/11/ 
reactivecocoa-tableview-binding.html 
• http://chris.eidhof.nl/posts/intentions.html 
• http://www.objc.io/issue-13/behaviors.html 
• http://www.objc.io/issue-13/viper.html

More Related Content

What's hot

AngularJS intro
AngularJS introAngularJS intro
AngularJS introdizabl
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginnersMunir Hoque
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular jsTamer Solieman
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at DatacomDavid Xi Peng Yang
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners WorkshopSathish VJ
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014Sarah Hudson
 
Rambler.iOS #5: Разбираем Massive View Controller
Rambler.iOS #5: Разбираем Massive View ControllerRambler.iOS #5: Разбираем Massive View Controller
Rambler.iOS #5: Разбираем Massive View ControllerRAMBLER&Co
 
AngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesMohamad Al Asmar
 
當ZK遇見Front-End
當ZK遇見Front-End當ZK遇見Front-End
當ZK遇見Front-End祁源 朱
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderSimon Massey
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JSBipin
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCBarry Gervin
 

What's hot (20)

AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginners
 
Introduction of angular js
Introduction of angular jsIntroduction of angular js
Introduction of angular js
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Rambler.iOS #5: Разбираем Massive View Controller
Rambler.iOS #5: Разбираем Massive View ControllerRambler.iOS #5: Разбираем Massive View Controller
Rambler.iOS #5: Разбираем Massive View Controller
 
5 angularjs features
5 angularjs features5 angularjs features
5 angularjs features
 
AngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key Features
 
當ZK遇見Front-End
當ZK遇見Front-End當ZK遇見Front-End
當ZK遇見Front-End
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-Binder
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
Angular js
Angular jsAngular js
Angular js
 
Angular js architecture (v1.4.8)
Angular js architecture (v1.4.8)Angular js architecture (v1.4.8)
Angular js architecture (v1.4.8)
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
 

Viewers also liked

Rambler.iOS #5: VIPER и Swift
Rambler.iOS #5: VIPER и SwiftRambler.iOS #5: VIPER и Swift
Rambler.iOS #5: VIPER и SwiftRAMBLER&Co
 
Introduction to VIPER Architecture
Introduction to VIPER ArchitectureIntroduction to VIPER Architecture
Introduction to VIPER ArchitectureHendy Christianto
 
Rambler.iOS #5: VIPER a la Rambler
Rambler.iOS #5: VIPER a la RamblerRambler.iOS #5: VIPER a la Rambler
Rambler.iOS #5: VIPER a la RamblerRAMBLER&Co
 
[SIP 2015] iOS Proposal: VIPER
[SIP 2015] iOS Proposal: VIPER[SIP 2015] iOS Proposal: VIPER
[SIP 2015] iOS Proposal: VIPERSilicon Straits
 
Viper - чистая архитектура iOS-приложения (И. Чирков)
Viper - чистая архитектура iOS-приложения (И. Чирков)Viper - чистая архитектура iOS-приложения (И. Чирков)
Viper - чистая архитектура iOS-приложения (И. Чирков)65apps
 
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)65apps
 
Clean architecture workshop
Clean architecture workshopClean architecture workshop
Clean architecture workshopJorge Ortiz
 
iOSアプリケーションアーキテクチャ選定の鍵を探す
iOSアプリケーションアーキテクチャ選定の鍵を探すiOSアプリケーションアーキテクチャ選定の鍵を探す
iOSアプリケーションアーキテクチャ選定の鍵を探すKenji Tanaka
 
Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Ken William
 
iOS Architecture
iOS ArchitectureiOS Architecture
iOS ArchitectureJacky Lian
 
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWeare-Legion
 
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPER
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPERRambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPER
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPERRAMBLER&Co
 
An (highly elementary) introduction to VIPER
An (highly elementary) introduction to VIPERAn (highly elementary) introduction to VIPER
An (highly elementary) introduction to VIPERdenicija
 
iOS Viper architecture for CocoaHeadsBY (RU)
iOS Viper architecture for CocoaHeadsBY (RU)iOS Viper architecture for CocoaHeadsBY (RU)
iOS Viper architecture for CocoaHeadsBY (RU)Vladimir Hudnitsky
 
Rambler.iOS #5: Переходы и передача данных между VIPER модулями
Rambler.iOS #5: Переходы и передача данных между VIPER модулямиRambler.iOS #5: Переходы и передача данных между VIPER модулями
Rambler.iOS #5: Переходы и передача данных между VIPER модулямиRAMBLER&Co
 
Dependence day insurgence
Dependence day insurgenceDependence day insurgence
Dependence day insurgenceJorge Ortiz
 
Why the Dark Side should use Swift and a SOLID Architecture
Why the Dark Side should use Swift and a SOLID ArchitectureWhy the Dark Side should use Swift and a SOLID Architecture
Why the Dark Side should use Swift and a SOLID ArchitectureJorge Ortiz
 

Viewers also liked (20)

VIPER - Design Pattern
VIPER - Design PatternVIPER - Design Pattern
VIPER - Design Pattern
 
Rambler.iOS #5: VIPER и Swift
Rambler.iOS #5: VIPER и SwiftRambler.iOS #5: VIPER и Swift
Rambler.iOS #5: VIPER и Swift
 
Introduction to VIPER Architecture
Introduction to VIPER ArchitectureIntroduction to VIPER Architecture
Introduction to VIPER Architecture
 
Rambler.iOS #5: VIPER a la Rambler
Rambler.iOS #5: VIPER a la RamblerRambler.iOS #5: VIPER a la Rambler
Rambler.iOS #5: VIPER a la Rambler
 
[SIP 2015] iOS Proposal: VIPER
[SIP 2015] iOS Proposal: VIPER[SIP 2015] iOS Proposal: VIPER
[SIP 2015] iOS Proposal: VIPER
 
Viper - чистая архитектура iOS-приложения (И. Чирков)
Viper - чистая архитектура iOS-приложения (И. Чирков)Viper - чистая архитектура iOS-приложения (И. Чирков)
Viper - чистая архитектура iOS-приложения (И. Чирков)
 
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)
ReactiveCocoa: делаем отзывчивое приложение (П. Руденко)
 
Clean architecture workshop
Clean architecture workshopClean architecture workshop
Clean architecture workshop
 
iOSアプリケーションアーキテクチャ選定の鍵を探す
iOSアプリケーションアーキテクチャ選定の鍵を探すiOSアプリケーションアーキテクチャ選定の鍵を探す
iOSアプリケーションアーキテクチャ選定の鍵を探す
 
Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~
 
iOS Architecture
iOS ArchitectureiOS Architecture
iOS Architecture
 
Viper architecture
Viper architectureViper architecture
Viper architecture
 
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
 
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPER
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPERRambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPER
Rambler.iOS #5: Генерамба и прочие аспекты кодогенерации в VIPER
 
An (highly elementary) introduction to VIPER
An (highly elementary) introduction to VIPERAn (highly elementary) introduction to VIPER
An (highly elementary) introduction to VIPER
 
iOS Viper architecture for CocoaHeadsBY (RU)
iOS Viper architecture for CocoaHeadsBY (RU)iOS Viper architecture for CocoaHeadsBY (RU)
iOS Viper architecture for CocoaHeadsBY (RU)
 
Rambler.iOS #5: Переходы и передача данных между VIPER модулями
Rambler.iOS #5: Переходы и передача данных между VIPER модулямиRambler.iOS #5: Переходы и передача данных между VIPER модулями
Rambler.iOS #5: Переходы и передача данных между VIPER модулями
 
Dependence day insurgence
Dependence day insurgenceDependence day insurgence
Dependence day insurgence
 
Why the Dark Side should use Swift and a SOLID Architecture
Why the Dark Side should use Swift and a SOLID ArchitectureWhy the Dark Side should use Swift and a SOLID Architecture
Why the Dark Side should use Swift and a SOLID Architecture
 
"Clean" Architecture
"Clean" Architecture"Clean" Architecture
"Clean" Architecture
 

Similar to From mvc to viper

Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGiuliano Iacobelli
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101Rich Helton
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSJinkyu Kim
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutAndoni Arroyo
 
深入淺出 MVC
深入淺出 MVC深入淺出 MVC
深入淺出 MVCJace Ju
 
D2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerD2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerWO Community
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentationBhavin Shah
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Patterngoodfriday
 
iPhone Programming in 30 minutes (?) [FTS]
iPhone Programming in 30 minutes (?) [FTS]iPhone Programming in 30 minutes (?) [FTS]
iPhone Programming in 30 minutes (?) [FTS]Diego Pizzocaro
 

Similar to From mvc to viper (20)

Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
iOS_Presentation
iOS_PresentationiOS_Presentation
iOS_Presentation
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockout
 
深入淺出 MVC
深入淺出 MVC深入淺出 MVC
深入淺出 MVC
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
D2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerD2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRoller
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
2013-01-10 iOS testing
2013-01-10 iOS testing2013-01-10 iOS testing
2013-01-10 iOS testing
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
I os 11
I os 11I os 11
I os 11
 
iPhone Programming in 30 minutes (?) [FTS]
iPhone Programming in 30 minutes (?) [FTS]iPhone Programming in 30 minutes (?) [FTS]
iPhone Programming in 30 minutes (?) [FTS]
 
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
JavaCro'14 - Vaadin web application integration for Enterprise systems – Pete...
 
iOS testing
iOS testingiOS testing
iOS testing
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

From mvc to viper

  • 1. from MVC to VIPER Krzysztof Profic @kprofic
  • 3. Pragmatic approach what hurts my eyes?
  • 4. Pragmatic approach what hurts my eyes? UIViewController
  • 6. 4 Steps • MVC on diet • MVVM • Intentions • VIPER
  • 7. 4 Steps • MVC on diet • MVVM • Intentions • VIPER
  • 8. MVC on diet Massive View Controller Light View Controller
  • 9. Reducing Massive ViewController • extract datasource • move domain logic into the model • move view code into the view layer objc.io #1
  • 10. Reducing Massive ViewController • extract datasource • move domain logic into the model • move view code into the view layer objc.io #1
  • 11. Reducing Massive ViewController • extract datasource • move domain logic into the model • move view code into the view layer objc.io #1
  • 12. Reducing Massive ViewController • Separation of concerns • Single responsibility principle objc.io #1
  • 13. Reanimate your MVC reduce MVC principles violation put ViewController on a diet
  • 14. What is the Rule?
  • 15. “Keep the code where it belongs”
  • 16. Layer
  • 17.
  • 18.
  • 19. Controllers Use Cases Entities Presenters Gateways UI DB External Interfaces Devices The Clean Architecture Enterprise Business Rules Application Business Rules Interface Adapters Frameworks & Drivers Web Controller Use Case Interactor Presenter Use Case Output Port Use Case Input Port Flow of control <I> <I> http://blog.8thlight.com
  • 20. separation of concerns = dividing software into … Layers
  • 21. “Keep the code on the right layer”
  • 23. Controllers Use Cases Entities Presenters Gateways UI DB External Interfaces Devices The Clean Architecture Enterprise Business Rules Application Business Rules Interface Adapters Frameworks & Drivers Web Controller Use Case Interactor Presenter Use Case Output Port Use Case Input Port Flow of control <I> <I> http://blog.8thlight.com
  • 26. MVVM
  • 27. 4 Steps • MVC on diet • MVVM • Intentions • VIPER
  • 29. - (void)viewDidLoad { [super viewDidLoad]; if (self.model.salutation.length > 0) { self.nameLabel.text = [NSString stringWithFormat:@"%@ %@ %@“, self.model.salutation, self.model.firstName, self.model.lastName]; } else { self.nameLabel.text = [NSString stringWithFormat:@"%@ %@“, self.model.firstName, self.model.lastName]; } NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEEE MMMM d, yyyy"]; self.birthdateLabel.text = [dateFormatter stringFromDate:model.birthdate]; } PersonViewController.m
  • 30. @implementation PersonViewModel - (instancetype)initWithPerson:(Person *)person { self = [super init]; if (!self) return nil; _person = person; if (person.salutation.length > 0) { _nameText = [NSString stringWithFormat:@"%@ %@ %@“, self.person.salutation, self.person.firstName, self.person.lastName]; } else { _nameText = [NSString stringWithFormat:@"%@ %@", self.person.firstName, self.person.lastName]; } NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEEE MMMM d, yyyy"]; _birthdateText = [dateFormatter stringFromDate:person.birthdate]; return self; } @end PersonViewModel.m
  • 31. - (void)viewDidLoad { [super viewDidLoad]; self.nameLabel.text = self.viewModel.nameText; self.birthdateLabel.text = self.viewModel.birthdateText; } PersonViewController.m
  • 32. 4 Steps • MVC on diet • MVVM • Intentions • VIPER
  • 33. Motivation • ViewController implements only viewWill* viewDid*
  • 34. • encapsulate small pieces of business logic • use case approach (form validation, login user) • hookable via & • reusable Intentions Architecture is about Intent “Uncle Bob” IBOutlet IBAction
  • 35.
  • 36. @interface ViewController () @property (strong) IBOutlet ModelContainer* modelContainer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; PersonViewModel * pvm = [[PersonViewModel alloc] initWithModel:self.person]; self.modelContainer.viewModel = pvm; } @end ViewController.m
  • 38. @interface ObserveIntention () @property (strong, nonatomic) IBOutlet id sourceObject; @property (strong, nonatomic) IBOutlet id target; @property (copy, nonatomic) IBOutlet NSString *sourceKeyPath; @property (copy, nonatomic) IBOutlet NSString *targetKeyPath; @end
  • 39. @implementation ObserveIntention - (void)awakeFromNib { [super awakeFromNib]; [self updateValue]; [self.sourceObject addObserver:self forKeyPath:self.sourceKeyPath options:0 context:nil]; } - (void)updateValue { id value = [self.sourceObject valueForKeyPath: self.sourceKeyPath]; if (self.targetKeyPath) { [self.target setValue:value forKeyPath:self.targetKeyPath]; } } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)obj change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:self.sourceKeyPath]) { [self updateValue]; } } @end
  • 40.
  • 42. Login
  • 43. User Story #90.10 - Login • A. When I as a user open the app the first time I enter the “main login” page, where I need to login with my username (email address) and password. • B. When I tap the “login button” while online and no errors occur I’m moved to initial page with users profile.
  • 44. User Story #90.10 - Login • A. When I as a user open the app the first time I enter the “main login” page, where I need to login with my username (email address) and password. • B. When I tap the “login button” while online and no errors occur I’m moved to initial page with users profile.
  • 45.
  • 46. @interface LoginIntention() @property (strong) IBOutlet UITextField * usernameTextField; @property (strong) IBOutlet UITextField * passwordTextField; @property (strong, nonatomic) IBOutlet UILabel * statusLabel; @end @implementation LoginIntention - (IBAction)login:(id)sender { self.statusLabel.text = @"connecting..."; [self sendActionsForControlEvents:UIControlEventValueChanged]; self.statusLabel.text = [NSString stringWithFormat:@"Authenticating %@“, self.usernameTextField.text]; [self sendActionsForControlEvents:UIControlEventValueChanged]; self.statusLabel.text = @"done"; [self sendActionsForControlEvents:UIControlEventValueChanged]; } @end LoginIntention.m
  • 47. @implementation LoginViewController - (IBAction)loginIntentionStateChanged:(LoginIntention *)sender { if ([sender.statusLabel.text isEqualToString:@"done"]){ [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; } } @end LoginViewController.m
  • 48. 4 Steps • MVC on diet • MVVM • Intentions • VIPER
  • 49. If you want more, checkout VIPER • View • Interactor • Presenter • Entity • Routing
  • 50. Summary: MVC on diet MVVM Intentions / Behaviours VIPER
  • 51. Thank you! Krzysztof Profic @kprofic
  • 52. • http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean- architecture.html • http://www.scottlogic.com/blog/2014/05/11/ reactivecocoa-tableview-binding.html • http://chris.eidhof.nl/posts/intentions.html • http://www.objc.io/issue-13/behaviors.html • http://www.objc.io/issue-13/viper.html