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

How to Write Clean Code in Android

Mohanraj K.M.
July 03, 2017
270

How to Write Clean Code in Android

Mohanraj K.M.

July 03, 2017
Tweet

Transcript

  1. Let's Start With Unit Testing • Typical Activity Class •

    Data retrieval • Data manipulation and decoration • UI-specific activities like rendering, painting, responding to user events, and the creation of fragments. • One class does all work • Massive Activity, Massive Fragment, Massive ViewController
  2. Can I Test them ? • Lets take data retrieval

    • All methods are intertwined • Doing everything everywhere • I need API provider • I need SQLite • I need to convert from datamodel to viewmodel • Mocking cannot rescue
  3. Does your App Architecture supports unit testing ? • Search

    for the testing tools • Forgetting the need
  4. Where to start ? • Clean architecture • VIPER •

    Force fitting in to Android • clean-swift
  5. Lets spilt the Monolithic Activity • Retrieve the data •

    Modify the model data according to viewmodel needs • Handle UI specific work • How they talk to each other ? • Interfaces • Unidirectional Flow
  6. Activity Unit Testing • Using Roboletric to simulate the Activity

    • Canary test • How do we test the Activity without Interactor?
  7. Interactor • Interactor retrieves the data from data sources like

    the local DB, web service, and content provider.
  8. Why we need Worker ? • If the task is

    simpler- No need • If you foresee that the task can be reused somewhere else in the app, move it to the Worker.