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

Refactoring to Kotlin - Kotlin/Everywhere

Wajahat Karim
December 28, 2019

Refactoring to Kotlin - Kotlin/Everywhere

Wajahat Karim delivers a talk about refactoring to Kotlin at Kotlin/Everywhere event organized by Android Pakistan Community (https://www.androidpakistancommunity.com/).

Full video of the talk is available at: https://www.youtube.com/watch?v=ciof7IiRAKw

Wajahat Karim

December 28, 2019
Tweet

More Decks by Wajahat Karim

Other Decks in Technology

Transcript

  1. Refactoring to Kotlin
    Wajahat Karim
    Moving Big Old Java Codebase to New Awesome Kotlin
    WajahatKarim

    View Slide

  2. I am Wajahat Karim
    And I work at Contour Software.
    Hey There!
    Coding
    8+ Years Experienced
    Android Developer
    Writing
    Authored 2 Worldwide
    Published Books
    Passion
    Open Source Contributor
    (many Android libraries)
    Community
    AndroidPub, FlutterPub,
    Articles, and Talks

    View Slide

  3. This is a story of...

    View Slide

  4. Messy Code
    Deprecated Libraries
    Frustrated Developers
    Not-so-happy Clients
    And Project X

    View Slide

  5. An Uber-like app for businesses (B2B)
    73+ screens and counting
    6+ different apps for each customer with own colors, server, features
    400+ classes (including Activity, Views, Models, POJOs)
    Existing codebase to work upon - Code modification takes double time.
    Project X

    View Slide

  6. What We Expected
    Modern APIs & Frameworks
    Some good architecture like MVP, MVVM etc.
    Well organized & commented code
    Unit & Instrumentation Tests

    View Slide

  7. What We Got
    Modern APIs & Frameworks - 2010 codebase never upgraded in years
    Some good architecture like MVP, MVVM etc. - Everything is in one BIG class.
    Well organized & commented code - Who has time for it?
    Unit & Instrumentation Tests - Sorry? What’s that? Never heard of it before.

    View Slide

  8. Old Code Architecture

    View Slide

  9. Let’s convert it Kotlin...
    CTRL + SHIFT + K

    View Slide

  10. View Slide

  11. New Code Architecture

    View Slide

  12. Refactor vs Rewrite
    No disturbance in existing features
    New features & bug fixes
    Tight deadlines & less time
    Too big risk to handle
    Refactoring

    View Slide

  13. What We Did
    1. Move all network code to Network Repository
    2. Move all local persistence code to Local Repository
    3. Move everything except UI, Navigation, & Business Logic to Common / Utils
    4. Create separate Activity/Fragment from big multiple-screen classes
    5. Integrate Kotlin & MVVM Core classes
    6. Move Business Logic to ViewModel

    View Slide

  14. 1. Unit & Instrumentation Testing
    2. CI/CD Automation
    3. Integrate Room database
    4. Integrate Retrofit + Coroutines
    What’s Next

    View Slide

  15. Show’em the code!

    View Slide

  16. Kotlin Extensions = ❤
    https://wajahatkarim.com/2019/03/-launching-activities-in-easier-way-using-kotlin-extensions-

    View Slide

  17. Domain Specific Language (DSL)
    Java
    Kotlin with DSL Builder
    https://android.jlelse.eu/domain-specific-language-dsl-using-kotlin-with-retrofit-example-9be5ef65a4fb

    View Slide

  18. @JVMStatic
    Kotlin
    Without @JVMStatic in Java
    With @JVMStatic in Java

    View Slide

  19. https://wajahatkarim.com [email protected]
    github.com/wajahatkarim3 @WajahatKarim
    Any Questions?
    medium.com/@wajahatkarim3

    View Slide