Clean Android Architecture

B1b15a8df73879b1d5eb247fee2028eb?s=47 Richa
April 10, 2015

Clean Android Architecture

Diving into problems with MVC and refactoring it into Clean Architecture - VIPER + MVVM, and talking about pros and cons of this architecture.

B1b15a8df73879b1d5eb247fee2028eb?s=128

Richa

April 10, 2015
Tweet

Transcript

  1. 3.
  2. 4.
  3. 5.
  4. 6.
  5. 7.
  6. 9.
  7. 10.
  8. 13.
  9. 14.

    MODEL VIEW CONTROLLER Interact with DB Render Model Handle view

    events Interact with API/cloud code Manage view state Update model Invoke another view Interact with system components Handle system events Update view based on system events
  10. 15.
  11. 16.

    View public class ExpandableCourseListActivity { public void onPause() { //

    save all expanded states } public void onResume() { // restore all expanded states } }
  12. 17.

    Controller public void onClick() {} public void onModelUpdated() {} public

    void onNewNotification() {} public void onLocationUpdated(Location location) {} public void takePhoto(Activity activityContext) {} public void launchProfilePage(Activity activityContext ) {}
  13. 18.
  14. 19.
  15. 20.
  16. 21.
  17. 22.

    MODEL VIEW CONTROLLER Interact with DB Render Model Handle view

    events Interact with API/cloud code Manage view state Update model Invoke another view Interact with system components Handle system events Update view based on system events
  18. 25.

    MODEL VIEW CONTROLLER INTERACTOR Retrieve data from Network Render Model

    Handle view events Interact with external entities Retrieve data from API/cloud code Manage view state Invoke another view Forward system events to view Forward model updates to view
  19. 28.

    MODEL VIEW CONTROLLER INTERACTOR VIEW MODEL Retrieve data from Network

    Render View Model Handle view events Interact with external entities Encapsulate view state and behavior Retrieve data from API/ cloud code Invoke another view Update view state
  20. 30.

    MODEL VIEW PRESENTER INTERACTOR VIEW MODEL Retrieve data from Network

    Render View Model Handle view events Interact with external entities Encapsulate view state and behavior Retrieve data from API/ cloud code Invoke another view Update view state
  21. 32.

    ENTITIES VIEW PRESENTER INTERACTOR VIEW MODEL Retrieve data from Data

    Sources Render View Model Handle view events Interact with external entities Encapsulate view state and behavior Invoke another view Update view state
  22. 33.
  23. 35.

    ENTITIES VIEW PRESENTER INTERACTOR VIEW MODEL ROUTER Retrieve data from

    Data Sources Render View Model Handle view events Interact with external entities Encapsulate view state and behavior Invoke another view Update view state
  24. 36.
  25. 38.
  26. 39.
  27. 40.
  28. 42.
  29. 51.
  30. 52.

    CatalogPresenter public void loadCatalog() { interactor.loadInteractor() .subscribe(new Action1<List<Course>>() { @Override

    public void call(List<Course> courses) { getData().mCourseList.onNext(courses); } }); }
  31. 54.

    CatalogViewModel public final BehaviorSubject<Catalog> catalog = BehaviorSubject.create(); public void subscribeToCatalog(Action1

    action) { catalog.subscribe(action); } public void unsubscribeToCatalog() { catalog.unsubscribe(action); }
  32. 55.

    CatalogInteractor Context mContext; public CatalogInteractor(Context context) { mContext = context;

    } public Observable loadCatalog() { return catalogDataSource.loadCatalog(); }
  33. 56.
  34. 57.
  35. 58.
  36. 59.
  37. 62.

    Build features in new architecture rather than refactor Validate Iterate

    - learn and apply Don’t refactor all the time
  38. 63.