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
Refactoring to Kotlin
Moving Big Old Java Codebase to New Awesome Kotlin
I am Wajahat Karim
And I work at Contour Software.
8+ Years Experienced
Authored 2 Worldwide
Open Source Contributor
(many Android libraries)
Articles, and Talks
This is a story of...
And Project X
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 modiﬁcation takes double time.
What We Expected
Modern APIs & Frameworks
Some good architecture like MVP, MVVM etc.
Well organized & commented code
Unit & Instrumentation Tests
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.
Old Code Architecture
Let’s convert it Kotlin...
CTRL + SHIFT + K
New Code Architecture
Refactor vs Rewrite
No disturbance in existing features
New features & bug ﬁxes
Tight deadlines & less time
Too big risk to handle
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
1. Unit & Instrumentation Testing
2. CI/CD Automation
3. Integrate Room database
4. Integrate Retroﬁt + Coroutines
Show’em the code!
Kotlin Extensions = ❤
Domain Speciﬁc Language (DSL)
Kotlin with DSL Builder
Without @JVMStatic in Java
With @JVMStatic in Java
https://wajahatkarim.com [email protected]