Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
MVP on Android: why do you need it?
Stan Kocken
May 02, 2016
Programming
1
140
MVP on Android: why do you need it?
Stan Kocken
May 02, 2016
Tweet
Share
More Decks by Stan Kocken
See All by Stan Kocken
Remote Control your App
stankocken
3
240
Unit Test your code, even your UI
stankocken
1
210
EfficientAdapter
stankocken
1
74
Other Decks in Programming
See All in Programming
ドメインモデル方式のクラス設計 座談会
masuda220
PRO
3
1k
git on intellij
hiroto_kitamura
0
160
Get Ready for Jakarta EE 10
ivargrimstad
0
1.4k
実践エクストリームプログラミング / Extreme Programming in Practice
enk
1
250
開発速度を5倍早くするVSCodeの拡張機能を作った
purp1eeeee
2
130
EFFICIENT CREATION OF AN EMPTY COLLECTION IN .NET
abt
0
150
Baseline Profilesでアプリのパフォーマンスを向上させる / Improve app performance with Baseline Profiles
numeroanddev
0
210
Android Tools & Performance
takahirom
1
410
こそこそアジャイル導入しようぜ!
ichimichi
0
1k
JetPackComposeは宣言型プログラミングパラダイムって実はよくわかってないんですが、別に使ってもいいんですよね、
conigashima
0
170
はてなフォトライフをECSに移行した話 / Hatena Engineer Seminar #20
cohalz
1
810
RFC 9111: HTTP Caching
jxck
0
150
Featured
See All Featured
What's new in Ruby 2.0
geeforr
336
30k
Designing for Performance
lara
597
63k
StorybookのUI Testing Handbookを読んだ
zakiyama
4
2.2k
Making Projects Easy
brettharned
98
4.3k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
11
4.7k
Thoughts on Productivity
jonyablonski
43
2.3k
Why Our Code Smells
bkeepers
PRO
324
55k
Stop Working from a Prison Cell
hatefulcrawdad
261
17k
Designing Experiences People Love
moore
130
22k
Rebuilding a faster, lazier Slack
samanthasiow
62
7.2k
Building Your Own Lightsaber
phodgson
94
4.6k
How to train your dragon (web standard)
notwaldorf
58
3.8k
Transcript
MVP: why do you need it? @stan_kocken
Join our team! dashlane.com/jobs Never forget another password Editor Choice
Top Developer 4.5/5 - 1M+ downloads
MVP: why do you need it?
Activity
BaseActivity: 1600+ lines A base activity that handles common functionality
in the app. This includes the navigation drawer, login and authentication, Action Bar tweaks, amongst others.
God Object
Activity
Activity/Fragments Usually contain: - actions on View - handle clicks
- read/write in database / SharePreference - network calls - …
Activity/Fragments Very hard to: - read - test - refactor
- reuse code - …
Separation of Concerns
Architecture MVP Model View Presenter state-change events updates view update
model user events
Architecture MVP: in Android, my way Model View Presenter
Architecture MVP: in Android, my way Model: access data store
state View Presenter
Architecture MVP: in Android, my way Model: access data store
state View Presenter: present data to UI
Architecture MVP: in Android, my way Model: access data store
state View: touch Android View no business logic Presenter: present data to UI
Architecture MVP: in Android, my way View: touch Android View
no business logic Presenter: present data to UI Model: DataProvider access data store state
Architecture MVP: in Android, my way Model: DataProvider access data
store state View: ViewProxy touch Android View no business logic Presenter: present data to UI
Presenter DataProvider ViewProxy Activity View Strong Reference Weak Reference Other
“Strong” Reference on DataProvider, Presenter or ViewProxy forbidden. Use WeakReference. Architecture MVP: in Android, my way
Example
DataProvider Presenter ViewProxy Creation refreshBoard() getGameBoard() setBoxValue( int x, int
y, int boxType);
DataProvider Presenter ViewProxy User click box onSelectBox(int x, int y)
play(int x, int y) refreshBoard() …
Definition public interface BoardDef { interface IPresenter extends BaseDef.IPresenter
{ void refreshBoard(); void onSelectBox(int x, int y); } interface IDataProvider extends BaseDef.IDataProvider { GameBoard getGameBoard(); void play(int x, int y); } interface IView extends BaseDef.IView { void setBoxValue(int x, int y, int boxType); } }
Test the UI Android stuffs TextView ImageView … View Proxy
Already Tested by framework team
Test the UI View Proxy Mock Mock Mock
@stan_kocken Presentation pattern: github.com/StanKocken/Presentation TicTacToe Example: github.com/StanKocken/TicTacToe