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

Android App Architecture - MCE2016

B1b15a8df73879b1d5eb247fee2028eb?s=47 Richa
April 22, 2016

Android App Architecture - MCE2016

B1b15a8df73879b1d5eb247fee2028eb?s=128

Richa

April 22, 2016
Tweet

Transcript

  1. Effective Android Architecture

  2. Hello! I am Richa Software Engineer at Coursera

  3. None
  4. ▪Challenges ▪Finding the right architecture fit ▪Validation ▪Demo and Samples

    ▪Cons ▪Key Takeaways Structure of the talk
  5. A can transform their life by accessing the world’s best

    learning experience. “
  6. Available on Google Play Store Place your screenshot here Android

    App 1,825+ COURSES 18M+ LEARNERS 141+ PARTNERS
  7. Single learning platform, multiple delivery mediums

  8. 109% increase in mobile usage since last year 24 %

    use mobile only 40 % use mobile and desktop
  9. Over 500k (and growing) new learners join Coursera every month

  10. Cross team Tightly aligned, loosely coupled Faster MVPs Learn fast,

    fail fast Network Speeds Edge, 2G, Spotty
  11. Who all has ever used MVC?

  12. MVC

  13. MVP ? MVC ? MVVM ?

  14. MODEL VIEW CONTROLLER Manage application data Render model Handle view

    events Interact with model Invoke next UI Table of Responsibilities
  15. Mobile Web Desktop

  16. None
  17. MODEL VIEW CONTROLLER Manage data from network Render model Handle

    view events Manage data from local storage Manage view state Interact with model Manage model consistency Navigation Interact with system components Interact with system events Update view on model changes or system events
  18. Model public class CourseModel { Course getFromDatabase() { // fetch

    from db, or local cache } Course getFromNetwork() { // fetch from apis, cache when possible } }
  19. View public class ExpandableCourseListActivity { void onSaveInstanceState(Bundle b) { //

    save all expanded states } }
  20. Controller void onClick() {} void onModelUpdated() {} void onNewNotification() {}

    void onLocationUpdated(Location loc) {} void takePhoto(Activity context) {} void launchView(Activity context ) {}
  21. None
  22. MVC ??

  23. MODEL VIEW CONTROLLER Manage data from local storage Render model

    Handle view events Manage data from network Manage view state Interact with model Manage model consistency Navigation Interact with system components Interact with system events Update view on model changes or system events
  24. Interactor?

  25. None
  26. MODEL VIEW CONTROLLER INTERACTOR Manage data from local storage Render

    view data Handle view events Interact with external entities Manage data from network Manage view data/ updates Navigation Manage model consistency Forward view data updates to view
  27. View Model ?

  28. None
  29. MODEL VIEW CONTROLLER INTERACTOR VIEW MODEL Manage data from local

    storage Render view model Handle view events Interact with external entities Manage view data Manage data from network Navigation Manage model consistency Manage view model
  30. Presenter ?

  31. MODEL VIEW PRESENTER INTERACTOR VIEW MODEL Manage data from local

    storage Render view model Handle view events Interact with external entities Manage view data Manage data from network Navigation Manage model consistency Manage view model
  32. Data Source

  33. ENTITIES VIEW PRESENTER INTERACTOR VIEW MODEL Represent model objects Render

    view model Handle view events Interact with external entities Manage view data Navigation Manage view model
  34. FlowController ?

  35. None
  36. ENTITIES VIEW PRESENTER INTERACTOR VIEW MODEL FLOW CONTROLLER Represent model

    objects Render view model Manage view events and view model Interact with external entities Manage view data Navigation
  37. None
  38. Apply Dependency Inversion

  39. None
  40. None
  41. None
  42. Espresso + Mocking JUnit + Mocking Android/ JUnit + Mocking

    Android/ JUnit + Mocks
  43. None
  44. Code Demo - Sample app

  45. Source Code https://github.com/richk/ CourseraDemoApp

  46. Classes • MainActivity • FlowController • CatalogActivity • CatalogPresenter •

    CatalogViewModel • CatalogInteractor
  47. MainActivity void onCreate() { FlowController.getInstance() .launchCatalogActivity(this); }

  48. FlowController void launchCatalogActivity(Context c) { Intent intent = …; c.startActivity(intent)

    }
  49. CatalogActivity CatalogPresenter presenter; void onCreate() { presenter = new CatalogPresenter(this);

    }
  50. CatalogActivity void onResume() { Action1<Catalog> action = ; presenter.subscribeToUpdates(action) }

  51. CatalogActivity void onPause() { presenter.unsubscribeToUpdates(); }

  52. CatalogPresenter CatalogInteractor interactor; CatalogPresenter(Context c) { viewModel = new CatalogViewModel();

    interactor = new CatalogInteractor(c); loadCatalog(); }
  53. CatalogPresenter void loadCatalog() { interactor.loadCourses().observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<>() { @Override public

    void call(List<Course> courses) { // update the view model } }); }
  54. CatalogViewModel // Parcelable public final Catalog catalog = new Catalog();

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

    } public Observable loadCatalog() { return catalogDataSource.loadCatalog(mContext.getApplication( )); }
  56. None
  57. The Cons

  58. Dealing with context Presenter(Context context) Interactor(Context context) NetworkClient(Context context) PersistenceClient(Context

    context) context.getSystemService(“SERVICE”) context.startActivity(intent) context.startActivityForResult(intent)
  59. Tedium ~ 4 classes per feature/module

  60. Adopting as a team Educating new hires

  61. Key Takeaways

  62. Ship the latest ideas

  63. Refactor or Not?

  64. Validate

  65. Iterate, Iterate, Iterate

  66. None
  67. We Are Hiring! Apply

  68. @richa123 rkhandelwal@coursera.org richk in/richak Thank You

  69. Questions ?