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

How to Write Clean Code in Android

1229b307f3c9c0f77db1493af36a2bad?s=47 Mohanraj K.M.
July 03, 2017
210

How to Write Clean Code in Android

1229b307f3c9c0f77db1493af36a2bad?s=128

Mohanraj K.M.

July 03, 2017
Tweet

Transcript

  1. android Clean Code Mohanraj Karatadipalayam @kmmraj

  2. 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
  3. 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
  4. Does your App Architecture supports unit testing ? • Search

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

    Force fitting in to Android • clean-swift
  6. Android Clean Code

  7. 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
  8. Activity

  9. Activity Unit Testing • Using Roboletric to simulate the Activity

    • Canary test • How do we test the Activity without Interactor?
  10. Activity Unit Testing

  11. Activity Unit Testing

  12. Interactor • Interactor retrieves the data from data sources like

    the local DB, web service, and content provider.
  13. 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.
  14. Testing Interactor • How to test Interactor with out Worker

    & Presenter
  15. Testing Interactor

  16. Presenter • Reduce the Model to VM

  17. Presenter

  18. Testing Presenter • FIRST • Fast • Isolated • Repeatable

    • Self-Validating • Timely
  19. Router • Determines the next screen • Pass the needed

    data to the next screen
  20. Testing Router

  21. Configurator

  22. Scaffolding

  23. What’s next? • Predictability • Developers can work across the

    technologies • Contribute • Refine