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

Kotlin Clean Code

Kotlin Clean Code

Are you an Android developer? Do you have huge monolithic fragments in your code? Are there too many non-testable classes? Are you faced with poor code coverages? Doesn’t this sound like a familiar story in Android app engineering? Kotlin Clean Code can help you solve these problems and improve the developer experience.

In this experiential talk, Mohanraj Karatadipalayam gives you a detailed overview of Kotlin Clean Code For Android, that enables the developers to write clean code, that has a good degree of separation of concerns and testability. He explores in detail, the need for Kotlin Clean Code for Android that makes programming more predictable. Using real examples and code snippets, Mohan highlights key challenges encountered while writing such apps and how he overcame them.

What actionable benefits/knowledge will attendees gain by attending your talk?
Key Takeaways from this talk include:
 
* Understanding the need for Kotlin Clean Code For Android
* Learn how it differs from other patterns
* Learn how to write apps using Kotlin Clean Code For Android
* Learn about how to code less and test more in an efficient manner

1229b307f3c9c0f77db1493af36a2bad?s=128

Mohanraj K.M.

April 22, 2019
Tweet

Transcript

  1. CONFIDENTIAL & RESTRICTED Mohanraj Karatadipalayam https://medium.com/@kmmraj

  2. CONFIDENTIAL & RESTRICTED PROBLEM Vs A B Incremental Changes Disruptive

    Changes
  3. CONFIDENTIAL & RESTRICTED HOW DO WE REACT? Tools Process Testing

    Designs
  4. CONFIDENTIAL & RESTRICTED Receptive to unit testing? Tools support Uses

    minimal mocking / no mocking at all Soup ? WHAT ABOUT APP ARCHITECTURE?
  5. CONFIDENTIAL & RESTRICTED UNIT TESTING OF APPS UNIT TESTING OF

    APPS Trivial ? Code coverage ? How much we test ?
  6. CONFIDENTIAL & RESTRICTED LET US START WITH UNIT TESTING o

    Functions are doing everything everywhere o Intertwined o Testing them ? o Mock it ?
  7. CONFIDENTIAL & RESTRICTED PERFECT UNIT TESTING FRAMEWORK • jUnit •

    Roboletric • fragment-testing androidx
  8. CONFIDENTIAL & RESTRICTED “One of the major reasons behind the

    failure of the unit test automation is an architecture of the app that does not support unit testing.”
  9. CONFIDENTIAL & RESTRICTED My Journey of finding a unit testable

    architecture
  10. CONFIDENTIAL & RESTRICTED Android code has a massive activity or

    fragment Typical fragment class do the below tasks Data retrieval from data sources Data manipulation and decoration UI Specific activities Life cycle UNIT TESTING IN APPS
  11. CONFIDENTIAL & RESTRICTED

  12. CONFIDENTIAL & RESTRICTED Native Mobile Development Patterns • MVMM •

    MVP • VIPER – View Interactor Presenter Entity Route • Clean Swift
  13. CONFIDENTIAL & RESTRICTED CLEAN SWIFT à CLEAN KOTLIN FOR ANDROID

  14. CONFIDENTIAL & RESTRICTED

  15. CONFIDENTIAL & RESTRICTED LET’S SPLIT IT UP 1 Get data

    from one or more data source à Interactor 2 Modify data in form that can be presented by the fragment à Presenter 3 Present data and listen to user events à Fragment
  16. CONFIDENTIAL & RESTRICTED Clean Kotlin - Incubation Uni - directional

  17. CONFIDENTIAL & RESTRICTED How they talk to each other Interfaces

  18. CONFIDENTIAL & RESTRICTED WHY INTERFACES? MOCK FAKE SPY

  19. CONFIDENTIAL & RESTRICTED LET’S GET STARTED

  20. CONFIDENTIAL & RESTRICTED CONFIGURATOR Does the wiring of the dependencies

    Worried about writing too many boilerplate codes?
  21. CONFIDENTIAL & RESTRICTED • Smoke test • how do we

    test the fragment without Interactor? LET’S TEST IT
  22. CONFIDENTIAL & RESTRICTED MORE TESTING

  23. CONFIDENTIAL & RESTRICTED • What is the work of Interactor?

    • data from the data sources like local DB, web service and content provider INTERACTOR
  24. CONFIDENTIAL & RESTRICTED INTERACTOR CODE

  25. CONFIDENTIAL & RESTRICTED • If the task is simpler, you

    can have all the work done by the Interactor itself. • When you foresee that the task can be reused somewhere else in the app, move it to the worker. WHAT IS THE NEED FOR THE WORKER?
  26. CONFIDENTIAL & RESTRICTED • Call back Hell ? • Use

    Rx | Kotlin Co routines WORKER
  27. CONFIDENTIAL & RESTRICTED • We don’t need a real worker,

    let’s create a spy. • And Spy for presenter INTERACTOR UNIT TESTING
  28. CONFIDENTIAL & RESTRICTED UNIT TEST IT — PIECE BY PIECE

  29. CONFIDENTIAL & RESTRICTED What is the work of Presenter? PRESENTER

  30. CONFIDENTIAL & RESTRICTED • Date of travel is in the

    YYYY/MM/DD PRESENTER
  31. CONFIDENTIAL & RESTRICTED PRESENTER

  32. CONFIDENTIAL & RESTRICTED • As usual -- Mock or Spy?

    PRESENTER UNIT TESTING
  33. CONFIDENTIAL & RESTRICTED PRESENTER UNIT TESTING

  34. CONFIDENTIAL & RESTRICTED ROUTER https://medium.com/@kmmraj

  35. CONFIDENTIAL & RESTRICTED ROUTER https://medium.com/@kmmraj

  36. CONFIDENTIAL & RESTRICTED UNIT TESTING ROUTER https://medium.com/@kmmraj

  37. CONFIDENTIAL & RESTRICTED CONFIGURATOR https://medium.com/@kmmraj

  38. CONFIDENTIAL & RESTRICTED TOO MUCH BOILERPLATE CODE? https://medium.com/@kmmraj

  39. CONFIDENTIAL & RESTRICTED References • https://medium.com/@kmmraj/kotlin-clean-code-for-android-series- f3b32307342d • http://bit.ly/KtlnCC4Drd •

    https://github.com/kmmraj/kt-clean-code4Android-generator • https://github.com/kmmraj/KotlinCleanCode4Android • https://clean-swift.com/ https://medium.com/@kmmraj