Rendra Toro - Model View Presenter
-
Upload
dicoding -
Category
Technology
-
view
831 -
download
4
Transcript of Rendra Toro - Model View Presenter
1
Model View Presenter
Indonesia
Malang, April 2016
Rendra Toro - Intel Innovator Software
2
why MVP
3
• Timeline very long for one task or feature on development
to release/live
• Need to change from Manual Test to Automated Testing
• It took a lot of time try to code Automated Testing
• New method Test Driven Development
Things we faced before using MVP
4
Model–view–presenter (MVP) is a derivation of the model–view–controller (MVC) architectural pattern, and is used mostly for building user interfaces.
5
MVP Diagram
VIEW
PRESENTER
MODEL
User Event Updates Views
Updates Model State-Change Events
6
Android Implementation
7
Models, Net, DataStoreFactory, Repositories, Model Mapper
Interfaces
Business Rules (App Workflow, Validation)
Interfaces
View View View View View View
Detail Ad PageHome Page Search Page Chat PageMyaccount Page Other Pages
VIEW
PRESENTER
MODEL
8
● Platform Specific View :
Fragment
Adapter
Activity
● Passive, limit action to model and presenter
View
9
View Diagrams
View Interface
Android Impl
Presenter
presenter.getListing()
view.showLoading() view.showRequestError() view.generateData()
2
1
3
Presenter Interface
view.showLoading()view.showRequestError()view.generateData()
presenter.getListing()
10
Presenter
● Business Rules happened here.
● Pure Java module without any android dependencies.
● Connection to, and from Presenter are done via interfaces
/ abstract class.
11
Presenter Diagrams
Model
View Interface
Presenter
Validation
Workflow
Interactors
Background Thread
onSuccess(Entity entity)
onFailed(Exception e)
RepositoriesInterface
Android Impl
2
3
4Presenter Interface
1
Other Java View Impl
presenter.getListing()
view.showLoading()view.showRequestError()view.generateData()
12
Model
● All data needed for the application are provided here via
Repository Implementation.
● DataStoreFactory responsible for loading data via cache
or API depends on the situation.
● Data origin is encapsulated from the client.
Model Diagrams
OlxService
CommunicationImpl
CommunicationInterface
APIDataSource StorageDataSource
Repositories
Storage
DataSource Interface
DataStoreFactory
PresenterRepositories
Interface1
2
3
14
Benefits
● Each class has single responsibility,
● Each layer can be tested,
● Abstraction,
● Scalable,
● Easy to maintain.
15
Road to Test Driven Development
● MVP
● Dependency Injection (Dagger 2)
● Unit Testing
16
Android Libraries
● Retrofit
● Butter Knife (View Injection)
● Dagger 2 (Dependency Injection)
Android Unit Test Libraries
● View - Espresso
● Presenter - JUnit, Mockito
● Model - Robolectric, JUnit, Mockito
17
References
http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/
https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
http://antonioleiva.com/mvp-android/
https://github.com/konmik/konmik.github.io/wiki/Introduction-to-Model-View-Presenter-on-Android
Sample Code
https://github.com/CommunityShareCode/MVP
18
Q & A