Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MVP on Android: why do you need it?

MVP on Android: why do you need it?

Stan Kocken

May 02, 2016
Tweet

More Decks by Stan Kocken

Other Decks in Programming

Transcript

  1. 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.
  2. Activity/Fragments Usually contain: - actions on View - handle clicks

    - read/write in database / SharePreference - network calls - …
  3. Architecture MVP: in Android, my way Model: access data store

    state View Presenter: present data to UI
  4. Architecture MVP: in Android, my way Model: access data store

    state View: touch Android View no business logic Presenter: present data to UI
  5. Architecture MVP: in Android, my way View: touch Android View

    no business logic Presenter: present data to UI Model: DataProvider access data store state
  6. 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
  7. 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
  8. 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);
 }
 }