SlideShare a Scribd company logo
1 of 43
Download to read offline
VIPER
Make your MVP cleaner
Dmytro Zaitsev
Senior Mobile Developer @ Lóhika
MVP/MVC/MVVM is NOT an
Architecture!
It’s only responsible for the presentation layer delivery mechanism
Real-world Android app
● Hard to understand
● Hard to maintain
● The business logic is mixed in Activity/Fragment
● High coupled components
● MVC -> Massive View Controllers
● Hard and often impossible to test
Clean Architecture
● Independent of Frameworks
● Testable
● Independent of Database
● Independent of any external agency
● Independent of UI
““
The Web is an I/O Device!
-Robert Martin
What is VIPER?
● A way of architecting applications which takes heavy inspiration
from the Clean Architecture
● Divides an app’s logical structure into distinct layers of
responsibility
● Makes it easier to isolate dependencies
● Makes it easier test the interactions at the boundaries between
layers
● Eliminates Massive View Controllers
Main parts of VIPER
● View
● Interactor
● Presenter
● Entity
● Router
View
Displays what it is told to by the Presenter and relays user input back
to the Presenter
View
● Is passive
● Waits for the Presenter to give it content to display
● Never asks the Presenter for data
● Determines how the content is displayed
● Handles user interaction and input
● Simply delegates user’s actions to the Presenter
● Awaits for a response telling it what should be displayed next
internal interface CheeseViewCallbacks {
fun onNewCheese(cheese: Collection<CheeseViewModel>)
fun showError()
fun hideProgress()
fun showProgress()
}
Example of View
class CheeseView : ConstraintLayout, CheeseViewCallbacks {
@Inject internal lateinit var presenter: CheesePresenter
private lateinit var progressDialog : ProgressDialog
private lateinit var adapter : CheeseAdapter
/** ... */
override fun onNewCheese(cheese: Collection<CheeseViewModel>) {
adapter.setModels(cheese)
adapter.notifyDataSetChanged()
}
override fun showError() {
Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show()
}
override fun hideProgress() = progressDialog.dismiss()
override fun showProgress() = progressDialog.show()
}
Example of View
Presenter
Contains view logic for preparing content for display (as received from
the Interactor) and for reacting to user inputs (by requesting new data
from the Interactor)
Presenter
● Knows about the content it maintains and when it should be
displayed
● Receives input events coming from the View
● Applies view logic over this data to prepare the content
● Tells the View what to display
● Sends requests to an Interactor
● Works like a bridge between the main parts of a VIPER module
● Receives the data structures coming from the Interactor
● Knows when to navigate to another screen, and which screen to
navigate to
class CheesePresenter(private val getCheeseInteractor: GetCheeseInteractor) {
var view: CheeseViewCallbacks? = null
var router: MainRouter? = null
/** ... */
fun fetchCheese(amount: Int) {
view?.showProgress()
getCheeseInteractor.execute({ cheese -> // onNext
view?.onNewCheeses(cheese)
view?.hideProgress()
},
{ // onError
view?.showError()
view?.hideProgress()
},
amount)
}
fun onItemClicked(model: CheeseViewModel) = router?.navigateToDetails(model)
}
Example of Presenter
Interactor
Contains the business logic as specified by a use case
Interactor
● Represents use cases
● Regular Java object
● No Android framework dependency
● Encapsulates application specific business rules
class GetCheeseInteractor @Inject constructor(
private val subscribeOn : Scheduler,
private val observeOn : Scheduler,
private val cheeseStorage: CheeseStorage) {
private val subscriptions = CompositeSubscription()
fun execute(subscriber: Subscriber<Collection<Cheese>>,
amount : Int) {
subscriptions.add(cheeseStorage.getCheese(amount)
.subscribeOn(subscribeOn)
.observeOn(observeOn)
.subscribe(subscriber))
}
}
Example of Interactor
Entity
Contains basic model objects used by the Interactor
Entity
● POJOs
● Encapsulates different types of data
● Model objects manipulated by an Interactor
data class Cheese(
val id : Long,
val name : String,
val price : Long,
val description : String,
val type : String,
val texture : String,
val fatContent : String,
val animalMilk : String,
val regionOfOrigin: String
)
Example of Entity
Router
Contains navigation logic for describing which screens are shown in
which order
Router
● Responsible for passing data between screens
● Receives input commands from the Presenter
● Responsible for the navigation logic between modules
internal interface MainRouter {
fun navigateToDetails(model: CheeseViewModel)
fun navigateToPreferences()
fun navigateToRegistration()
}
Example of Router
class MainActivity : AppCompatActivity(), MainRouter {
override fun navigateToDetails(model: CheeseViewModel) {
startActivity(Intent(this, DetailsActivity::class.java).apply {
with(this) {
putExtra(DetailsActivity.NAME, model.name)
putExtra(DetailsActivity.CHECKED, model.isChecked)
}
})
}
override fun navigateToPreferences() {
startActivity(Intent(this, SettingsActivity::class.java))
}
override fun navigateToRegistration() {
supportFragmentManager.beginTransaction()
.replace(R.id.content, LoginFragment())
.commit()
}
}
Example of Router
Why should you use VIPER?
● It’s easier to track issues via crash reports
● The source code will be cleaner, more compact and reusable
● Adding new features is easier
● There are less conflicts with the rest of the development team
● It’s easier to write automated tests
When should you NOT use VIPER?
● It’s an overkill for small projects
● Causes an overhead when starting new projects
● MVP/MVC/MVVM-VIPER mix can cause headaches
● Lots of code all over the project
Testing
● Presentation layer
○ Espresso, Robolectric
● Domain layer
○ JUnit, Mockito, PowerMock
● Data layer
○ Robolectric, JUnit, Mockito, PowerMock
References
● http://mutualmobile.github.io/blog/2013/12/04/viper-introduction/
● http://www.mttnow.com/blog/architecting-mobile-apps-with-bviper-modules
● http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/
● http://fernandocejas.com/2015/07/18/architecting-android-the-evolution/
● https://www.objc.io/issues/13-architecture/viper/
● https://github.com/RxViper/RxViper
● https://www.ckl.io/blog/ios-project-architecture-using-viper/
● http://luboganev.github.io/post/clean-architecture-pt2/
Demo
Dmytro Zaitsev
@DmitriyZaitsev
Questions?
Thank you!

More Related Content

What's hot

Managing parallelism using coroutines
Managing parallelism using coroutinesManaging parallelism using coroutines
Managing parallelism using coroutinesFabio Collini
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxVisual Engineering
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC AnnotationsJordan Silva
 
Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databindingBoulos Dib
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose worldFabio Collini
 
Powerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatisPowerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatissimonetripodi
 
Deep dive into Android Data Binding
Deep dive into Android Data BindingDeep dive into Android Data Binding
Deep dive into Android Data BindingRadek Piekarz
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightMichael Pustovit
 
Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4soelinn
 
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
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmFabio Collini
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)Yurii Kotov
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩GDG Korea
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confFabio Collini
 
Data binding в массы!
Data binding в массы!Data binding в массы!
Data binding в массы!Artjoker
 
ASP.NET MVC Controllers & Actions
ASP.NET MVC Controllers & ActionsASP.NET MVC Controllers & Actions
ASP.NET MVC Controllers & Actionsonsela
 

What's hot (20)

Managing parallelism using coroutines
Managing parallelism using coroutinesManaging parallelism using coroutines
Managing parallelism using coroutines
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC Annotations
 
Knockoutjs databinding
Knockoutjs databindingKnockoutjs databinding
Knockoutjs databinding
 
Architectures in the compose world
Architectures in the compose worldArchitectures in the compose world
Architectures in the compose world
 
Powerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatisPowerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatis
 
Deep dive into Android Data Binding
Deep dive into Android Data BindingDeep dive into Android Data Binding
Deep dive into Android Data Binding
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 light
 
Asp.NET MVC
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
 
React with Redux
React with ReduxReact with Redux
React with Redux
 
Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4
 
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
 
Kotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere StockholmKotlin delegates in practice - Kotlin Everywhere Stockholm
Kotlin delegates in practice - Kotlin Everywhere Stockholm
 
Data binding в массы! (1.2)
Data binding в массы! (1.2)Data binding в массы! (1.2)
Data binding в массы! (1.2)
 
안드로이드 데이터 바인딩
안드로이드 데이터 바인딩안드로이드 데이터 바인딩
안드로이드 데이터 바인딩
 
React 101
React 101React 101
React 101
 
Kotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community confKotlin Delegates in practice - Kotlin community conf
Kotlin Delegates in practice - Kotlin community conf
 
Data binding в массы!
Data binding в массы!Data binding в массы!
Data binding в массы!
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
ASP.NET MVC Controllers & Actions
ASP.NET MVC Controllers & ActionsASP.NET MVC Controllers & Actions
ASP.NET MVC Controllers & Actions
 

Viewers also liked

οι πρώτοι χριστιανοί
οι πρώτοι χριστιανοίοι πρώτοι χριστιανοί
οι πρώτοι χριστιανοί70athinon
 
Cómo las tecnologías emergentes
Cómo las tecnologías emergentesCómo las tecnologías emergentes
Cómo las tecnologías emergentesJjmorenomor
 
Archimedia core competencies
Archimedia core competenciesArchimedia core competencies
Archimedia core competencieskirolos fawzy
 
SE2016 Java Dmitriy Kouperman "Working with legacy systems. Stabilization, mo...
SE2016 Java Dmitriy Kouperman "Working with legacy systems. Stabilization, mo...SE2016 Java Dmitriy Kouperman "Working with legacy systems. Stabilization, mo...
SE2016 Java Dmitriy Kouperman "Working with legacy systems. Stabilization, mo...Inhacking
 

Viewers also liked (15)

Collection in java
Collection in javaCollection in java
Collection in java
 
Javabeginners
JavabeginnersJavabeginners
Javabeginners
 
Jesse owens
Jesse owensJesse owens
Jesse owens
 
Concurency
ConcurencyConcurency
Concurency
 
Jvmjava
JvmjavaJvmjava
Jvmjava
 
6java switch
6java switch6java switch
6java switch
 
Java projectchangeworld
Java projectchangeworldJava projectchangeworld
Java projectchangeworld
 
οι πρώτοι χριστιανοί
οι πρώτοι χριστιανοίοι πρώτοι χριστιανοί
οι πρώτοι χριστιανοί
 
Cómo las tecnologías emergentes
Cómo las tecnologías emergentesCómo las tecnologías emergentes
Cómo las tecnologías emergentes
 
Archimedia core competencies
Archimedia core competenciesArchimedia core competencies
Archimedia core competencies
 
SE2016 Java Dmitriy Kouperman "Working with legacy systems. Stabilization, mo...
SE2016 Java Dmitriy Kouperman "Working with legacy systems. Stabilization, mo...SE2016 Java Dmitriy Kouperman "Working with legacy systems. Stabilization, mo...
SE2016 Java Dmitriy Kouperman "Working with legacy systems. Stabilization, mo...
 
Java encapsulation
Java encapsulationJava encapsulation
Java encapsulation
 
Exception Handling.
Exception Handling.Exception Handling.
Exception Handling.
 
Learn java
Learn javaLearn java
Learn java
 
Know javaimportance
Know javaimportanceKnow javaimportance
Know javaimportance
 

Similar to SE2016 Android Dmytro Zaitsev "Viper make your MVP cleaner"

Five android architecture
Five android architectureFive android architecture
Five android architectureTomislav Homan
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Patternmaddinapudi
 
MvvmQuickCross for Windows Phone
MvvmQuickCross for Windows PhoneMvvmQuickCross for Windows Phone
MvvmQuickCross for Windows PhoneVincent Hoogendoorn
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWAREFIWARE
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019iFour Technolab Pvt. Ltd.
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Alessandro Molina
 
MBLTDev15: Egor Tolstoy, Rambler&Co
MBLTDev15: Egor Tolstoy, Rambler&CoMBLTDev15: Egor Tolstoy, Rambler&Co
MBLTDev15: Egor Tolstoy, Rambler&Coe-Legion
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter rendra toro
 
Do iOS Presentation - Mobile app architectures
Do iOS Presentation - Mobile app architecturesDo iOS Presentation - Mobile app architectures
Do iOS Presentation - Mobile app architecturesDavid Broža
 
MongoDB Stitch Tutorial
MongoDB Stitch TutorialMongoDB Stitch Tutorial
MongoDB Stitch TutorialMongoDB
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidOutware Mobile
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WAREFermin Galan
 
Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008SteveMillidge
 
Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019UA Mobile
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalDroidcon Berlin
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)Jose Manuel Pereira Garcia
 

Similar to SE2016 Android Dmytro Zaitsev "Viper make your MVP cleaner" (20)

Five android architecture
Five android architectureFive android architecture
Five android architecture
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Pattern
 
MvvmQuickCross for Windows Phone
MvvmQuickCross for Windows PhoneMvvmQuickCross for Windows Phone
MvvmQuickCross for Windows Phone
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
 
Conductor vs Fragments
Conductor vs FragmentsConductor vs Fragments
Conductor vs Fragments
 
MBLTDev15: Egor Tolstoy, Rambler&Co
MBLTDev15: Egor Tolstoy, Rambler&CoMBLTDev15: Egor Tolstoy, Rambler&Co
MBLTDev15: Egor Tolstoy, Rambler&Co
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter
 
Do iOS Presentation - Mobile app architectures
Do iOS Presentation - Mobile app architecturesDo iOS Presentation - Mobile app architectures
Do iOS Presentation - Mobile app architectures
 
MongoDB Stitch Tutorial
MongoDB Stitch TutorialMongoDB Stitch Tutorial
MongoDB Stitch Tutorial
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
 
Frontend training
Frontend trainingFrontend training
Frontend training
 
Clean Architecture @ Taxibeat
Clean Architecture @ TaxibeatClean Architecture @ Taxibeat
Clean Architecture @ Taxibeat
 
Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008
 
Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019Working effectively with ViewModels and TDD - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 

More from Inhacking

SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"
SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"
SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"Inhacking
 
SE2016 Fundraising Wlodek Laskowski "Insider guide to successful fundraising ...
SE2016 Fundraising Wlodek Laskowski "Insider guide to successful fundraising ...SE2016 Fundraising Wlodek Laskowski "Insider guide to successful fundraising ...
SE2016 Fundraising Wlodek Laskowski "Insider guide to successful fundraising ...Inhacking
 
SE2016 Fundraising Andrey Sobol "Blockchain Crowdfunding or "Mommy, look, I l...
SE2016 Fundraising Andrey Sobol "Blockchain Crowdfunding or "Mommy, look, I l...SE2016 Fundraising Andrey Sobol "Blockchain Crowdfunding or "Mommy, look, I l...
SE2016 Fundraising Andrey Sobol "Blockchain Crowdfunding or "Mommy, look, I l...Inhacking
 
SE2016 Company Development Valentin Dombrovsky "Travel startups challenges an...
SE2016 Company Development Valentin Dombrovsky "Travel startups challenges an...SE2016 Company Development Valentin Dombrovsky "Travel startups challenges an...
SE2016 Company Development Valentin Dombrovsky "Travel startups challenges an...Inhacking
 
SE2016 Company Development Vadym Gorenko "How to pass the death valley"
SE2016 Company Development Vadym Gorenko  "How to pass the death valley"SE2016 Company Development Vadym Gorenko  "How to pass the death valley"
SE2016 Company Development Vadym Gorenko "How to pass the death valley"Inhacking
 
SE2016 Marketing&PR Jan Keil "Do the right thing marketing for startups"
SE2016 Marketing&PR Jan Keil "Do the right thing marketing for startups"SE2016 Marketing&PR Jan Keil "Do the right thing marketing for startups"
SE2016 Marketing&PR Jan Keil "Do the right thing marketing for startups"Inhacking
 
SE2016 PR&Marketing Mikhail Patalakha "ASO how to start and how to finish"
SE2016 PR&Marketing Mikhail Patalakha "ASO how to start and how to finish"SE2016 PR&Marketing Mikhail Patalakha "ASO how to start and how to finish"
SE2016 PR&Marketing Mikhail Patalakha "ASO how to start and how to finish"Inhacking
 
SE2016 UI/UX Alina Kononenko "Designing for Apple Watch and Apple TV"
SE2016 UI/UX Alina Kononenko "Designing for Apple Watch and Apple TV"SE2016 UI/UX Alina Kononenko "Designing for Apple Watch and Apple TV"
SE2016 UI/UX Alina Kononenko "Designing for Apple Watch and Apple TV"Inhacking
 
SE2016 Management Mikhail Lebedinkiy "iAIST the first pure ukrainian corporat...
SE2016 Management Mikhail Lebedinkiy "iAIST the first pure ukrainian corporat...SE2016 Management Mikhail Lebedinkiy "iAIST the first pure ukrainian corporat...
SE2016 Management Mikhail Lebedinkiy "iAIST the first pure ukrainian corporat...Inhacking
 
SE2016 Management Anna Lavrova "Gladiator in the suit crisis is our brand!"
SE2016 Management Anna Lavrova "Gladiator in the suit  crisis is our brand!"SE2016 Management Anna Lavrova "Gladiator in the suit  crisis is our brand!"
SE2016 Management Anna Lavrova "Gladiator in the suit crisis is our brand!"Inhacking
 
SE2016 Management Aleksey Solntsev "Management of the projects in the conditi...
SE2016 Management Aleksey Solntsev "Management of the projects in the conditi...SE2016 Management Aleksey Solntsev "Management of the projects in the conditi...
SE2016 Management Aleksey Solntsev "Management of the projects in the conditi...Inhacking
 
SE2016 Management Vitalii Laptenok "Processes and planning for a product comp...
SE2016 Management Vitalii Laptenok "Processes and planning for a product comp...SE2016 Management Vitalii Laptenok "Processes and planning for a product comp...
SE2016 Management Vitalii Laptenok "Processes and planning for a product comp...Inhacking
 
SE2016 Management Yana Prolis "Please don't burn down!"
SE2016 Management Yana Prolis "Please don't burn down!"SE2016 Management Yana Prolis "Please don't burn down!"
SE2016 Management Yana Prolis "Please don't burn down!"Inhacking
 
SE2016 Management Marina Bril "Management at marketing teams and performance"
SE2016 Management Marina Bril "Management at marketing teams and performance"SE2016 Management Marina Bril "Management at marketing teams and performance"
SE2016 Management Marina Bril "Management at marketing teams and performance"Inhacking
 
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"Inhacking
 
SE2016 iOS Alexander Voronov "Test driven development in real world"
SE2016 iOS Alexander Voronov "Test driven development in real world"SE2016 iOS Alexander Voronov "Test driven development in real world"
SE2016 iOS Alexander Voronov "Test driven development in real world"Inhacking
 
SE2016 JS Gregory Shehet "Undefined on prod, or how to test a react application"
SE2016 JS Gregory Shehet "Undefined on prod, or how to test a react application"SE2016 JS Gregory Shehet "Undefined on prod, or how to test a react application"
SE2016 JS Gregory Shehet "Undefined on prod, or how to test a react application"Inhacking
 
SE2016 JS Alexey Osipenko "Basics of functional reactive programming"
SE2016 JS Alexey Osipenko "Basics of functional reactive programming"SE2016 JS Alexey Osipenko "Basics of functional reactive programming"
SE2016 JS Alexey Osipenko "Basics of functional reactive programming"Inhacking
 
SE2016 Java Vladimir Mikhel "Scrapping the web"
SE2016 Java Vladimir Mikhel "Scrapping the web"SE2016 Java Vladimir Mikhel "Scrapping the web"
SE2016 Java Vladimir Mikhel "Scrapping the web"Inhacking
 
SE2016 Java Valerii Moisieienko "Apache HBase Workshop"
SE2016 Java Valerii Moisieienko "Apache HBase Workshop"SE2016 Java Valerii Moisieienko "Apache HBase Workshop"
SE2016 Java Valerii Moisieienko "Apache HBase Workshop"Inhacking
 

More from Inhacking (20)

SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"
SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"
SE2016 Fundraising Roman Kravchenko "Investment in Ukrainian IoT-Startups"
 
SE2016 Fundraising Wlodek Laskowski "Insider guide to successful fundraising ...
SE2016 Fundraising Wlodek Laskowski "Insider guide to successful fundraising ...SE2016 Fundraising Wlodek Laskowski "Insider guide to successful fundraising ...
SE2016 Fundraising Wlodek Laskowski "Insider guide to successful fundraising ...
 
SE2016 Fundraising Andrey Sobol "Blockchain Crowdfunding or "Mommy, look, I l...
SE2016 Fundraising Andrey Sobol "Blockchain Crowdfunding or "Mommy, look, I l...SE2016 Fundraising Andrey Sobol "Blockchain Crowdfunding or "Mommy, look, I l...
SE2016 Fundraising Andrey Sobol "Blockchain Crowdfunding or "Mommy, look, I l...
 
SE2016 Company Development Valentin Dombrovsky "Travel startups challenges an...
SE2016 Company Development Valentin Dombrovsky "Travel startups challenges an...SE2016 Company Development Valentin Dombrovsky "Travel startups challenges an...
SE2016 Company Development Valentin Dombrovsky "Travel startups challenges an...
 
SE2016 Company Development Vadym Gorenko "How to pass the death valley"
SE2016 Company Development Vadym Gorenko  "How to pass the death valley"SE2016 Company Development Vadym Gorenko  "How to pass the death valley"
SE2016 Company Development Vadym Gorenko "How to pass the death valley"
 
SE2016 Marketing&PR Jan Keil "Do the right thing marketing for startups"
SE2016 Marketing&PR Jan Keil "Do the right thing marketing for startups"SE2016 Marketing&PR Jan Keil "Do the right thing marketing for startups"
SE2016 Marketing&PR Jan Keil "Do the right thing marketing for startups"
 
SE2016 PR&Marketing Mikhail Patalakha "ASO how to start and how to finish"
SE2016 PR&Marketing Mikhail Patalakha "ASO how to start and how to finish"SE2016 PR&Marketing Mikhail Patalakha "ASO how to start and how to finish"
SE2016 PR&Marketing Mikhail Patalakha "ASO how to start and how to finish"
 
SE2016 UI/UX Alina Kononenko "Designing for Apple Watch and Apple TV"
SE2016 UI/UX Alina Kononenko "Designing for Apple Watch and Apple TV"SE2016 UI/UX Alina Kononenko "Designing for Apple Watch and Apple TV"
SE2016 UI/UX Alina Kononenko "Designing for Apple Watch and Apple TV"
 
SE2016 Management Mikhail Lebedinkiy "iAIST the first pure ukrainian corporat...
SE2016 Management Mikhail Lebedinkiy "iAIST the first pure ukrainian corporat...SE2016 Management Mikhail Lebedinkiy "iAIST the first pure ukrainian corporat...
SE2016 Management Mikhail Lebedinkiy "iAIST the first pure ukrainian corporat...
 
SE2016 Management Anna Lavrova "Gladiator in the suit crisis is our brand!"
SE2016 Management Anna Lavrova "Gladiator in the suit  crisis is our brand!"SE2016 Management Anna Lavrova "Gladiator in the suit  crisis is our brand!"
SE2016 Management Anna Lavrova "Gladiator in the suit crisis is our brand!"
 
SE2016 Management Aleksey Solntsev "Management of the projects in the conditi...
SE2016 Management Aleksey Solntsev "Management of the projects in the conditi...SE2016 Management Aleksey Solntsev "Management of the projects in the conditi...
SE2016 Management Aleksey Solntsev "Management of the projects in the conditi...
 
SE2016 Management Vitalii Laptenok "Processes and planning for a product comp...
SE2016 Management Vitalii Laptenok "Processes and planning for a product comp...SE2016 Management Vitalii Laptenok "Processes and planning for a product comp...
SE2016 Management Vitalii Laptenok "Processes and planning for a product comp...
 
SE2016 Management Yana Prolis "Please don't burn down!"
SE2016 Management Yana Prolis "Please don't burn down!"SE2016 Management Yana Prolis "Please don't burn down!"
SE2016 Management Yana Prolis "Please don't burn down!"
 
SE2016 Management Marina Bril "Management at marketing teams and performance"
SE2016 Management Marina Bril "Management at marketing teams and performance"SE2016 Management Marina Bril "Management at marketing teams and performance"
SE2016 Management Marina Bril "Management at marketing teams and performance"
 
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"
SE2016 iOS Anton Fedorchenko "Swift for Server-side Development"
 
SE2016 iOS Alexander Voronov "Test driven development in real world"
SE2016 iOS Alexander Voronov "Test driven development in real world"SE2016 iOS Alexander Voronov "Test driven development in real world"
SE2016 iOS Alexander Voronov "Test driven development in real world"
 
SE2016 JS Gregory Shehet "Undefined on prod, or how to test a react application"
SE2016 JS Gregory Shehet "Undefined on prod, or how to test a react application"SE2016 JS Gregory Shehet "Undefined on prod, or how to test a react application"
SE2016 JS Gregory Shehet "Undefined on prod, or how to test a react application"
 
SE2016 JS Alexey Osipenko "Basics of functional reactive programming"
SE2016 JS Alexey Osipenko "Basics of functional reactive programming"SE2016 JS Alexey Osipenko "Basics of functional reactive programming"
SE2016 JS Alexey Osipenko "Basics of functional reactive programming"
 
SE2016 Java Vladimir Mikhel "Scrapping the web"
SE2016 Java Vladimir Mikhel "Scrapping the web"SE2016 Java Vladimir Mikhel "Scrapping the web"
SE2016 Java Vladimir Mikhel "Scrapping the web"
 
SE2016 Java Valerii Moisieienko "Apache HBase Workshop"
SE2016 Java Valerii Moisieienko "Apache HBase Workshop"SE2016 Java Valerii Moisieienko "Apache HBase Workshop"
SE2016 Java Valerii Moisieienko "Apache HBase Workshop"
 

Recently uploaded

Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝soniya singh
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...wyqazy
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Niamh verma
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 

Recently uploaded (7)

Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 

SE2016 Android Dmytro Zaitsev "Viper make your MVP cleaner"

  • 1. VIPER Make your MVP cleaner Dmytro Zaitsev Senior Mobile Developer @ Lóhika
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. MVP/MVC/MVVM is NOT an Architecture! It’s only responsible for the presentation layer delivery mechanism
  • 9. Real-world Android app ● Hard to understand ● Hard to maintain ● The business logic is mixed in Activity/Fragment ● High coupled components ● MVC -> Massive View Controllers ● Hard and often impossible to test
  • 10.
  • 11. Clean Architecture ● Independent of Frameworks ● Testable ● Independent of Database ● Independent of any external agency ● Independent of UI
  • 12. ““ The Web is an I/O Device! -Robert Martin
  • 13.
  • 14.
  • 15. What is VIPER? ● A way of architecting applications which takes heavy inspiration from the Clean Architecture ● Divides an app’s logical structure into distinct layers of responsibility ● Makes it easier to isolate dependencies ● Makes it easier test the interactions at the boundaries between layers ● Eliminates Massive View Controllers
  • 16. Main parts of VIPER ● View ● Interactor ● Presenter ● Entity ● Router
  • 17.
  • 18. View Displays what it is told to by the Presenter and relays user input back to the Presenter
  • 19. View ● Is passive ● Waits for the Presenter to give it content to display ● Never asks the Presenter for data ● Determines how the content is displayed ● Handles user interaction and input ● Simply delegates user’s actions to the Presenter ● Awaits for a response telling it what should be displayed next
  • 20. internal interface CheeseViewCallbacks { fun onNewCheese(cheese: Collection<CheeseViewModel>) fun showError() fun hideProgress() fun showProgress() } Example of View
  • 21.
  • 22. class CheeseView : ConstraintLayout, CheeseViewCallbacks { @Inject internal lateinit var presenter: CheesePresenter private lateinit var progressDialog : ProgressDialog private lateinit var adapter : CheeseAdapter /** ... */ override fun onNewCheese(cheese: Collection<CheeseViewModel>) { adapter.setModels(cheese) adapter.notifyDataSetChanged() } override fun showError() { Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show() } override fun hideProgress() = progressDialog.dismiss() override fun showProgress() = progressDialog.show() } Example of View
  • 23. Presenter Contains view logic for preparing content for display (as received from the Interactor) and for reacting to user inputs (by requesting new data from the Interactor)
  • 24. Presenter ● Knows about the content it maintains and when it should be displayed ● Receives input events coming from the View ● Applies view logic over this data to prepare the content ● Tells the View what to display ● Sends requests to an Interactor ● Works like a bridge between the main parts of a VIPER module ● Receives the data structures coming from the Interactor ● Knows when to navigate to another screen, and which screen to navigate to
  • 25. class CheesePresenter(private val getCheeseInteractor: GetCheeseInteractor) { var view: CheeseViewCallbacks? = null var router: MainRouter? = null /** ... */ fun fetchCheese(amount: Int) { view?.showProgress() getCheeseInteractor.execute({ cheese -> // onNext view?.onNewCheeses(cheese) view?.hideProgress() }, { // onError view?.showError() view?.hideProgress() }, amount) } fun onItemClicked(model: CheeseViewModel) = router?.navigateToDetails(model) } Example of Presenter
  • 26. Interactor Contains the business logic as specified by a use case
  • 27. Interactor ● Represents use cases ● Regular Java object ● No Android framework dependency ● Encapsulates application specific business rules
  • 28. class GetCheeseInteractor @Inject constructor( private val subscribeOn : Scheduler, private val observeOn : Scheduler, private val cheeseStorage: CheeseStorage) { private val subscriptions = CompositeSubscription() fun execute(subscriber: Subscriber<Collection<Cheese>>, amount : Int) { subscriptions.add(cheeseStorage.getCheese(amount) .subscribeOn(subscribeOn) .observeOn(observeOn) .subscribe(subscriber)) } } Example of Interactor
  • 29. Entity Contains basic model objects used by the Interactor
  • 30. Entity ● POJOs ● Encapsulates different types of data ● Model objects manipulated by an Interactor
  • 31. data class Cheese( val id : Long, val name : String, val price : Long, val description : String, val type : String, val texture : String, val fatContent : String, val animalMilk : String, val regionOfOrigin: String ) Example of Entity
  • 32. Router Contains navigation logic for describing which screens are shown in which order
  • 33.
  • 34.
  • 35. Router ● Responsible for passing data between screens ● Receives input commands from the Presenter ● Responsible for the navigation logic between modules
  • 36. internal interface MainRouter { fun navigateToDetails(model: CheeseViewModel) fun navigateToPreferences() fun navigateToRegistration() } Example of Router
  • 37. class MainActivity : AppCompatActivity(), MainRouter { override fun navigateToDetails(model: CheeseViewModel) { startActivity(Intent(this, DetailsActivity::class.java).apply { with(this) { putExtra(DetailsActivity.NAME, model.name) putExtra(DetailsActivity.CHECKED, model.isChecked) } }) } override fun navigateToPreferences() { startActivity(Intent(this, SettingsActivity::class.java)) } override fun navigateToRegistration() { supportFragmentManager.beginTransaction() .replace(R.id.content, LoginFragment()) .commit() } } Example of Router
  • 38. Why should you use VIPER? ● It’s easier to track issues via crash reports ● The source code will be cleaner, more compact and reusable ● Adding new features is easier ● There are less conflicts with the rest of the development team ● It’s easier to write automated tests
  • 39. When should you NOT use VIPER? ● It’s an overkill for small projects ● Causes an overhead when starting new projects ● MVP/MVC/MVVM-VIPER mix can cause headaches ● Lots of code all over the project
  • 40. Testing ● Presentation layer ○ Espresso, Robolectric ● Domain layer ○ JUnit, Mockito, PowerMock ● Data layer ○ Robolectric, JUnit, Mockito, PowerMock
  • 41. References ● http://mutualmobile.github.io/blog/2013/12/04/viper-introduction/ ● http://www.mttnow.com/blog/architecting-mobile-apps-with-bviper-modules ● http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/ ● http://fernandocejas.com/2015/07/18/architecting-android-the-evolution/ ● https://www.objc.io/issues/13-architecture/viper/ ● https://github.com/RxViper/RxViper ● https://www.ckl.io/blog/ios-project-architecture-using-viper/ ● http://luboganev.github.io/post/clean-architecture-pt2/
  • 42. Demo