SlideShare a Scribd company logo
VIPER ON ANDROID
Gabriel B. Zandavalle
Thiago “Fred” Porciúncula
• Clean Architecture
• What is VIPER
• Cases
• Code samples
• Cons e Pros
• Architecture Components
• Questions
CLEAN ARCHITECTURE | WHAT IT IS?
https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html
CLEAN ARCHITECTURE | WHAT IT IS?
VIPER
CLEAN ARCHITECTURE | VIPER
VIPER IS AN APPLICATION OF CLEAN ARCHITECTURE
TO IOS APPS (AND NOW ANDROID!)
V - View
I - Interactor
P - Presenter
E - Entity
R - Routing
VIPER | WHAT DOES IT MEAN?
VIEW
Displays what it is told to by the Presenter and relays
user input back to the Presenter.
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).
INTERACTOR
Contains the business logic as specified by a use case.
ENTITY
Contains basic model objects used by the Interactor.
ROUTING
Contains navigation logic for describing which
screens are shown in which order.
VIPER | MODULE
WHY VIPER ON ANDROID?
CASES | UBER
https://eng.uber.com/new-rider-app/
CASES | UBER
CASES | BRAGI
http://luboganev.github.io/blog/clean-architecture-pt1/
CASES | COURSERA
https://news.realm.io/news/360andev-richa-khandelwal-effective-
android-architecture-patterns-java/
CASES | COURSERA
CASES | COURSERA
CASES | COURSERA
View Presenter Interactor
Router
Dagger
Entity
VIPER | MODULE
HomeActivity
HomePresenterOutput
HomePresenter HomeInteractor
HomePresenterInput
HomeInteractorOutput
HomeInteractorInput
class HomeContracts {



interface HomePresenterInput {

fun viewLoaded()

}

interface HomeInteractorInput {

fun loadMovies()

}


interface HomeInteractorOutput {

fun moviesLoaded(items: List<Movie>)

}


interface HomePresenterOutput {

fun showMovies(items: List<Movie>)

}

}
VIPER | CONTRACTS
class HomeContracts {



interface HomePresenterInput {

fun viewLoaded()

}

interface HomeInteractorInput {

fun loadMovies()

}


interface HomeInteractorOutput {

fun moviesLoaded(items: List<Movie>)

}


interface HomePresenterOutput {

fun showMovies(items: List<Movie>)

}

}
VIPER | CONTRACTS
HomeActivity
HomePresenterOutpu
HomePresenter HomeInteractor
HomePresenterInput
HomeInteractorOutpu
HomeInteractorInput
class HomeActivity: AppCompatActivity(), HomeContracts.HomePresenterOutput {



@Inject

lateinit var homePresenterInput: HomeContracts.HomePresenterInput



override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_home)
injectDependencies()



homePresenterInput.viewLoaded()

}



override fun showMovies(items: List<Movie>) {

moviesRecyclerView.adapter = MovieAdapter(items)

moviesRecyclerView.layoutManager = LinearLayoutManager(this)

}

}
VIPER | VIEW
class HomeActivity: AppCompatActivity(), HomeContracts.HomePresenterOutput {



@Inject

lateinit var homePresenterInput: HomeContracts.HomePresenterInput



override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_home)
injectDependencies()



homePresenterInput.viewLoaded()

}



override fun showMovies(items: List<Movie>) {

moviesRecyclerView.adapter = MovieAdapter(items)

moviesRecyclerView.layoutManager = LinearLayoutManager(this)

}

}
VIPER | VIEW
HomeActivity
HomePresenterOutpu
HomePresenter HomeInteractor
HomePresenterInput
HomeInteractorOutpu
HomeInteractorInput
viewLoaded()
showMovies()
VIPER | PRESENTER
class HomePresenter(
private val homePresenterOutput: HomePresenterOutput,
private val homeInteractorInput: HomeInteractorInput) :

HomePresenterInput, HomeInteractorOutput {



override fun viewLoaded() {

homeInteractorInput.loadMovies()

}



override fun moviesLoaded(items: List<Movie>) {

homePresenterOutput.showMovies(items)

}

}
VIPER | PRESENTER
class HomePresenter(
private val homePresenterOutput: HomePresenterOutput,
private val homeInteractorInput: HomeInteractorInput) :

HomePresenterInput, HomeInteractorOutput {



override fun viewLoaded() {

homeInteractorInput.loadMovies()

}



override fun moviesLoaded(items: List<Movie>) {

homePresenterOutput.showMovies(items)

}

}
HomeActivity
HomePresenterOutpu
HomePresenter HomeInteractor
HomePresenterInput
HomeInteractorOutpu
HomeInteractorInput
viewLoaded() loadMovies()
moviesLoaded()showMovies()
VIPER | INTERACTOR
class HomeInteractor(private val moviesApi: MoviesAPI) : HomeInteractorInput {



lateinit var homeInteractorOutput: HomeInteractorOutput



override fun loadMovies() {

moviesApi.getList("1", "api_key").subscribe ({

homeInteractorOutput.moviesLoaded(it.items)

}, {

Log.e(TAG, "Error loading movies", it)

})

}

}
VIPER | INTERACTOR
class HomeInteractor(private val moviesApi: MoviesAPI) : HomeInteractorInput {



lateinit var homeInteractorOutput: HomeInteractorOutput



override fun loadMovies() {

moviesApi.getList("1", "api_key").subscribe ({

homeInteractorOutput.moviesLoaded(it.items)

}, {

Log.e(TAG, "Error loading movies", it)

})

}

}
HomeActivity
HomePresenterOutpu
HomePresenter HomeInteractor
HomePresenterInput
HomeInteractorOutpu
HomeInteractorInput
loadMovies()
moviesLoaded()
VIPER | ENTITY
data class Movie(

val id: String = "",

val posterPath: String = "",

val title: String = "",

val overview: String = "",

val releaseDate : String = ""

)

}
VIPER | ROUTER
class HomeRouter(private val context: Context) { 



fun navigateToDetail(id: String) {

val intent = Intent(context, DetailActivity::class.java)

intent.putExtra(
DetailActivity.EXTRA_SELECTED_MOVIE_ID, id)

context.startActivity(intent)

}

}

VIPER | TESTS
@Mock

lateinit var homePresenterOutput: HomeContracts.HomePresenterOutput


@Mock

lateinit var homeInteractorInput: HomeContracts.HomeInteractorInput



@Before

fun setUp() {

MockitoAnnotations.initMocks(this)

homePresenter = HomePresenter(homePresenterOutput, homeInteractorInput)

homePresenter.setPresenterOutput(homePresenterOutput)



given(homeInteractorInput.loadMovies()).will { homePresenter.moviesLoaded(movies) }

}
VIPER | TESTS
@Test

fun shouldLoadMoviesWhenViewIsLoaded() {

homePresenter.viewLoaded()

verify(homeInteractorInput).loadMovies()

}



@Test

fun shouldShowMoviesWhenMoviesAreLoaded() {

homePresenter.moviesLoaded(movies)

verify(homePresenterOutput).showMovies(movies)

}
VIPER | MODULES
VIPER | CONS
VIPER | CONS
• Overkill for small projects
VIPER | CONS
• Overkill for small projects
• Overhead for inexperienced teams and risk of
mixing it with different strategies (MVP/MVC/
MVVM)
VIPER | CONS
• Overkill for small projects
• Overhead for inexperienced teams and risk of
mixing it with different strategies (MVP/MVC/
MVVM)
• Tedious modules creation without code generators
VIPER | CONS
• Overkill for small projects
• Overhead for inexperienced teams and risk of
mixing it with different strategies (MVP/MVC/
MVVM)
• Tedious modules creation without code generators
• Might not be a perfect fit for any kind of project
VIPER | PROS
VIPER | PROS
• Improved responsibility balance
VIPER | PROS
• Improved responsibility balance
• Well-defined contracts
VIPER | PROS
• Improved responsibility balance
• Well-defined contracts
• Smaller classes and methods
VIPER | PROS
• Improved responsibility balance
• Well-defined contracts
• Smaller classes and methods
• Easier to test
VIPER | PROS
• Improved responsibility balance
• Well-defined contracts
• Smaller classes and methods
• Easier to test
• Easier to maintain and add new features
VIPER | PROS
• Improved responsibility balance
• Well-defined contracts
• Smaller classes and methods
• Easier to test
• Easier to maintain and add new features
• Possibility to use the same architecture between
iOS and Android projects
ANDROID ARCHITECTURE
COMPONENTES
SECTION | ARCHITECTURE COMPONENTS
"The most important thing you
should focus on is the separation of
concerns in your app.”
https://developer.android.com/topic/libraries/architecture/guide.html
View
Presenter?
Interactor
Model
SECTION | PRESENTER vs VIEWMODEL
SECTION | PRESENTER vs VIEWMODEL
• Both are responsible for preparing the data for
the UI
SECTION | PRESENTER vs VIEWMODEL
• Both are responsible for preparing the data for
the UI
• The Presenter has a reference to the view, while
ViewModel doesn’t
SECTION | PRESENTER vs VIEWMODEL
• Both are responsible for preparing the data for
the UI
• The Presenter has a reference to the view, while
ViewModel doesn’t
• The ViewModel enables data binding
SECTION | PRESENTER vs VIEWMODEL
• Both are responsible for preparing the data for
the UI
• The Presenter has a reference to the view, while
ViewModel doesn’t
• The ViewModel enables data binding
• The ViewModel provides observable data to the
view
SECTION | ARCHITECTURE COMPONENTS
"If your UI is complex, consider creating a
Presenter class to handle UI modifications.
This is usually overkill, but might make
your UIs easier to test."
VIPER | CONCLUSION
"It is impossible to have
one way of writing apps
that will be the best for
every scenario. (…) If you
already have a good way
of writing Android apps,
you don't need to change."
https://github.com/arctouch-gabrielzandavalle/tmdbviper
OBRIGADO
We are hiring !

More Related Content

Similar to Viper on Android

Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Lucas Jellema
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsug
Toshiaki Maki
 
Building maintainable app
Building maintainable appBuilding maintainable app
Building maintainable app
Kristijan Jurković
 
Android Widget
Android WidgetAndroid Widget
Android Widget
ELLURU Kalyan
 
Building maintainable app #droidconzg
Building maintainable app #droidconzgBuilding maintainable app #droidconzg
Building maintainable app #droidconzg
Kristijan Jurković
 
iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...
iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...
iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...
mfrancis
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best Practices
Solstice Mobile Argentina
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter
rendra toro
 
Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017
Melania Andrisan (Danciu)
 
Thoughts on Component Resuse
Thoughts on Component ResuseThoughts on Component Resuse
Thoughts on Component Resuse
Justin Edelson
 
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
CodelyTV
 
Unity and Azure Mobile Services using Prime31 plugin
Unity and Azure Mobile Services using Prime31 pluginUnity and Azure Mobile Services using Prime31 plugin
Unity and Azure Mobile Services using Prime31 plugin
David Douglas
 
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyRed Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Mark Proctor
 
Advanced #6 clean architecture
Advanced #6  clean architectureAdvanced #6  clean architecture
Advanced #6 clean architecture
Vitali Pekelis
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
Imam Raza
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose React
Oliver N
 
From Containerization to Modularity
From Containerization to ModularityFrom Containerization to Modularity
From Containerization to Modularity
oasisfeng
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
BruceLee275640
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
Fwdays
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos
 

Similar to Viper on Android (20)

Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
Oracle JavaScript Extension Toolkit Web Components Bring Agility to App Devel...
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsug
 
Building maintainable app
Building maintainable appBuilding maintainable app
Building maintainable app
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
Building maintainable app #droidconzg
Building maintainable app #droidconzgBuilding maintainable app #droidconzg
Building maintainable app #droidconzg
 
iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...
iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...
iPOJO - The Simple Life - Richard Hall, Visiting Assistant Professor at Tufts...
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best Practices
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter
 
Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017Serverless Single Page Apps with React and Redux at ItCamp 2017
Serverless Single Page Apps with React and Redux at ItCamp 2017
 
Thoughts on Component Resuse
Thoughts on Component ResuseThoughts on Component Resuse
Thoughts on Component Resuse
 
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
 
Unity and Azure Mobile Services using Prime31 plugin
Unity and Azure Mobile Services using Prime31 pluginUnity and Azure Mobile Services using Prime31 plugin
Unity and Azure Mobile Services using Prime31 plugin
 
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client TechnologyRed Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
Red Hat JBoss BRMS and BPMS Workbench and Rich Client Technology
 
Advanced #6 clean architecture
Advanced #6  clean architectureAdvanced #6  clean architecture
Advanced #6 clean architecture
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose React
 
From Containerization to Modularity
From Containerization to ModularityFrom Containerization to Modularity
From Containerization to Modularity
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 

Recently uploaded

Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
confluent
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Luigi Fugaro
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
michniczscribd
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
Luigi Fugaro
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
Paul Brebner
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
narinav14
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
Optimizing Your E-commerce with WooCommerce.pptx
Optimizing Your E-commerce with WooCommerce.pptxOptimizing Your E-commerce with WooCommerce.pptx
Optimizing Your E-commerce with WooCommerce.pptx
WebConnect Pvt Ltd
 
TMU毕业证书精仿办理
TMU毕业证书精仿办理TMU毕业证书精仿办理
TMU毕业证书精仿办理
aeeva
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
Zycus
 

Recently uploaded (20)

Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
Optimizing Your E-commerce with WooCommerce.pptx
Optimizing Your E-commerce with WooCommerce.pptxOptimizing Your E-commerce with WooCommerce.pptx
Optimizing Your E-commerce with WooCommerce.pptx
 
TMU毕业证书精仿办理
TMU毕业证书精仿办理TMU毕业证书精仿办理
TMU毕业证书精仿办理
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
 

Viper on Android

  • 1. VIPER ON ANDROID Gabriel B. Zandavalle Thiago “Fred” Porciúncula
  • 2. • Clean Architecture • What is VIPER • Cases • Code samples • Cons e Pros • Architecture Components • Questions
  • 3. CLEAN ARCHITECTURE | WHAT IT IS? https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html
  • 4. CLEAN ARCHITECTURE | WHAT IT IS?
  • 5.
  • 6.
  • 8. CLEAN ARCHITECTURE | VIPER VIPER IS AN APPLICATION OF CLEAN ARCHITECTURE TO IOS APPS (AND NOW ANDROID!)
  • 9. V - View I - Interactor P - Presenter E - Entity R - Routing VIPER | WHAT DOES IT MEAN?
  • 10. VIEW Displays what it is told to by the Presenter and relays user input back to the Presenter.
  • 11. 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).
  • 12. INTERACTOR Contains the business logic as specified by a use case.
  • 13. ENTITY Contains basic model objects used by the Interactor.
  • 14. ROUTING Contains navigation logic for describing which screens are shown in which order.
  • 16. WHY VIPER ON ANDROID?
  • 25. VIPER | MODULE HomeActivity HomePresenterOutput HomePresenter HomeInteractor HomePresenterInput HomeInteractorOutput HomeInteractorInput
  • 26. class HomeContracts {
 
 interface HomePresenterInput {
 fun viewLoaded()
 }
 interface HomeInteractorInput {
 fun loadMovies()
 } 
 interface HomeInteractorOutput {
 fun moviesLoaded(items: List<Movie>)
 } 
 interface HomePresenterOutput {
 fun showMovies(items: List<Movie>)
 }
 } VIPER | CONTRACTS
  • 27. class HomeContracts {
 
 interface HomePresenterInput {
 fun viewLoaded()
 }
 interface HomeInteractorInput {
 fun loadMovies()
 } 
 interface HomeInteractorOutput {
 fun moviesLoaded(items: List<Movie>)
 } 
 interface HomePresenterOutput {
 fun showMovies(items: List<Movie>)
 }
 } VIPER | CONTRACTS HomeActivity HomePresenterOutpu HomePresenter HomeInteractor HomePresenterInput HomeInteractorOutpu HomeInteractorInput
  • 28. class HomeActivity: AppCompatActivity(), HomeContracts.HomePresenterOutput {
 
 @Inject
 lateinit var homePresenterInput: HomeContracts.HomePresenterInput
 
 override fun onCreate(savedInstanceState: Bundle?) {
 super.onCreate(savedInstanceState)
 setContentView(R.layout.activity_home) injectDependencies()
 
 homePresenterInput.viewLoaded()
 }
 
 override fun showMovies(items: List<Movie>) {
 moviesRecyclerView.adapter = MovieAdapter(items)
 moviesRecyclerView.layoutManager = LinearLayoutManager(this)
 }
 } VIPER | VIEW
  • 29. class HomeActivity: AppCompatActivity(), HomeContracts.HomePresenterOutput {
 
 @Inject
 lateinit var homePresenterInput: HomeContracts.HomePresenterInput
 
 override fun onCreate(savedInstanceState: Bundle?) {
 super.onCreate(savedInstanceState)
 setContentView(R.layout.activity_home) injectDependencies()
 
 homePresenterInput.viewLoaded()
 }
 
 override fun showMovies(items: List<Movie>) {
 moviesRecyclerView.adapter = MovieAdapter(items)
 moviesRecyclerView.layoutManager = LinearLayoutManager(this)
 }
 } VIPER | VIEW HomeActivity HomePresenterOutpu HomePresenter HomeInteractor HomePresenterInput HomeInteractorOutpu HomeInteractorInput viewLoaded() showMovies()
  • 30. VIPER | PRESENTER class HomePresenter( private val homePresenterOutput: HomePresenterOutput, private val homeInteractorInput: HomeInteractorInput) :
 HomePresenterInput, HomeInteractorOutput {
 
 override fun viewLoaded() {
 homeInteractorInput.loadMovies()
 }
 
 override fun moviesLoaded(items: List<Movie>) {
 homePresenterOutput.showMovies(items)
 }
 }
  • 31. VIPER | PRESENTER class HomePresenter( private val homePresenterOutput: HomePresenterOutput, private val homeInteractorInput: HomeInteractorInput) :
 HomePresenterInput, HomeInteractorOutput {
 
 override fun viewLoaded() {
 homeInteractorInput.loadMovies()
 }
 
 override fun moviesLoaded(items: List<Movie>) {
 homePresenterOutput.showMovies(items)
 }
 } HomeActivity HomePresenterOutpu HomePresenter HomeInteractor HomePresenterInput HomeInteractorOutpu HomeInteractorInput viewLoaded() loadMovies() moviesLoaded()showMovies()
  • 32. VIPER | INTERACTOR class HomeInteractor(private val moviesApi: MoviesAPI) : HomeInteractorInput {
 
 lateinit var homeInteractorOutput: HomeInteractorOutput
 
 override fun loadMovies() {
 moviesApi.getList("1", "api_key").subscribe ({
 homeInteractorOutput.moviesLoaded(it.items)
 }, {
 Log.e(TAG, "Error loading movies", it)
 })
 }
 }
  • 33. VIPER | INTERACTOR class HomeInteractor(private val moviesApi: MoviesAPI) : HomeInteractorInput {
 
 lateinit var homeInteractorOutput: HomeInteractorOutput
 
 override fun loadMovies() {
 moviesApi.getList("1", "api_key").subscribe ({
 homeInteractorOutput.moviesLoaded(it.items)
 }, {
 Log.e(TAG, "Error loading movies", it)
 })
 }
 } HomeActivity HomePresenterOutpu HomePresenter HomeInteractor HomePresenterInput HomeInteractorOutpu HomeInteractorInput loadMovies() moviesLoaded()
  • 34. VIPER | ENTITY data class Movie(
 val id: String = "",
 val posterPath: String = "",
 val title: String = "",
 val overview: String = "",
 val releaseDate : String = ""
 )
 }
  • 35. VIPER | ROUTER class HomeRouter(private val context: Context) { 
 
 fun navigateToDetail(id: String) {
 val intent = Intent(context, DetailActivity::class.java)
 intent.putExtra( DetailActivity.EXTRA_SELECTED_MOVIE_ID, id)
 context.startActivity(intent)
 }
 }

  • 36. VIPER | TESTS @Mock
 lateinit var homePresenterOutput: HomeContracts.HomePresenterOutput 
 @Mock
 lateinit var homeInteractorInput: HomeContracts.HomeInteractorInput
 
 @Before
 fun setUp() {
 MockitoAnnotations.initMocks(this)
 homePresenter = HomePresenter(homePresenterOutput, homeInteractorInput)
 homePresenter.setPresenterOutput(homePresenterOutput)
 
 given(homeInteractorInput.loadMovies()).will { homePresenter.moviesLoaded(movies) }
 }
  • 37. VIPER | TESTS @Test
 fun shouldLoadMoviesWhenViewIsLoaded() {
 homePresenter.viewLoaded()
 verify(homeInteractorInput).loadMovies()
 }
 
 @Test
 fun shouldShowMoviesWhenMoviesAreLoaded() {
 homePresenter.moviesLoaded(movies)
 verify(homePresenterOutput).showMovies(movies)
 }
  • 40. VIPER | CONS • Overkill for small projects
  • 41. VIPER | CONS • Overkill for small projects • Overhead for inexperienced teams and risk of mixing it with different strategies (MVP/MVC/ MVVM)
  • 42. VIPER | CONS • Overkill for small projects • Overhead for inexperienced teams and risk of mixing it with different strategies (MVP/MVC/ MVVM) • Tedious modules creation without code generators
  • 43. VIPER | CONS • Overkill for small projects • Overhead for inexperienced teams and risk of mixing it with different strategies (MVP/MVC/ MVVM) • Tedious modules creation without code generators • Might not be a perfect fit for any kind of project
  • 45. VIPER | PROS • Improved responsibility balance
  • 46. VIPER | PROS • Improved responsibility balance • Well-defined contracts
  • 47. VIPER | PROS • Improved responsibility balance • Well-defined contracts • Smaller classes and methods
  • 48. VIPER | PROS • Improved responsibility balance • Well-defined contracts • Smaller classes and methods • Easier to test
  • 49. VIPER | PROS • Improved responsibility balance • Well-defined contracts • Smaller classes and methods • Easier to test • Easier to maintain and add new features
  • 50. VIPER | PROS • Improved responsibility balance • Well-defined contracts • Smaller classes and methods • Easier to test • Easier to maintain and add new features • Possibility to use the same architecture between iOS and Android projects
  • 52. SECTION | ARCHITECTURE COMPONENTS "The most important thing you should focus on is the separation of concerns in your app.” https://developer.android.com/topic/libraries/architecture/guide.html
  • 53.
  • 55. SECTION | PRESENTER vs VIEWMODEL
  • 56. SECTION | PRESENTER vs VIEWMODEL • Both are responsible for preparing the data for the UI
  • 57. SECTION | PRESENTER vs VIEWMODEL • Both are responsible for preparing the data for the UI • The Presenter has a reference to the view, while ViewModel doesn’t
  • 58. SECTION | PRESENTER vs VIEWMODEL • Both are responsible for preparing the data for the UI • The Presenter has a reference to the view, while ViewModel doesn’t • The ViewModel enables data binding
  • 59. SECTION | PRESENTER vs VIEWMODEL • Both are responsible for preparing the data for the UI • The Presenter has a reference to the view, while ViewModel doesn’t • The ViewModel enables data binding • The ViewModel provides observable data to the view
  • 60. SECTION | ARCHITECTURE COMPONENTS "If your UI is complex, consider creating a Presenter class to handle UI modifications. This is usually overkill, but might make your UIs easier to test."
  • 61.
  • 62. VIPER | CONCLUSION "It is impossible to have one way of writing apps that will be the best for every scenario. (…) If you already have a good way of writing Android apps, you don't need to change."