How to not only make apps, but how to make good apps with architecture that easy to understand, easy to maintain, and easy to change.
https://youtu.be/60tbLQzS8g4?t=6776
Engine() fun start() { engine.start() } } fun main() { val car = Car() car.start() } • With DI class Car(private val engine: Engine){ fun start() { engine.start() } } fun main() { val engine = Engine() val car = Car(engine) car.start() } DI Manual Manual DI
{ lateinit var engine: Engine override fun onCreate(...) { ... engine = Engine() val car = Car(engine) car.start() } } • After class MainActivity : AppCompatActivity() { val engine: Engine by inject() override fun onCreate(...) { ... val car = Car(engine) car.start() } }
{ lateinit var engine: Engine override fun onCreate(...) { ... engine = Engine() val car = Car(engine) car.start() } } • After class MainActivity : AppCompatActivity() { @Inject lateinit var engine: Engine override fun onCreate(...) { appComponent.inject(this) ... val car = Car(engine) car.start() } }
AppCompatActivity() { lateinit var engine: Engine override fun onCreate(...) { ... engine = Engine() val car = Car(engine) car.start() } } • After @AndroidEntryPoint class MainActivity : AppCompatActivity() { @Inject lateinit var engine: Engine override fun onCreate(...) { ... val car = Car(engine) car.start() } }
lebih cepat • Code ownership • Reusability • Lebih aman ketika crash • Batasan yang lebih jelas daripada package • Bisa membuat Instant App dan Dynamic Feature Replace Me! (Bisa ditambahkan dengan image yang relevan)
supaya kode lebih mudah dikembangkan • Pelajari Reactive Programming supaya kode lebih mudah dipahami • Pelajari Dependency Injection supaya kode lebih mudah digunakan kembali • Pelajari Modularization supaya kode lebih mudah dikelola