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

The D in SOLID Principles

ValentineRutto
November 12, 2023
200

The D in SOLID Principles

This is a codelab covering how to use KOIN, Manual and HILT Dependency Injection. The Demo application is built with Kotlin following MVVM architecture , it consumes tmdb api . https://github.com/valentineRutto/Movies/tree/droidconugdemo

ValentineRutto

November 12, 2023
Tweet

Transcript

  1. S.O.L.I.D Principles Set of design guidelines to follow when building

    software so that it's easier to scale and maintain. • S -ingle responsibility A class should have a single responsibility • O-pen-Closed Classes should be open for extension, but closed for modification • L-iskov substitiution Objects of parent Class or its child Class can be used in the same way without any errors. • I-nterface segregation Clients should not be forced to depend on methods that they do not use. • D -ependency Inversion High-level modules should not depend on low-level modules but depend on abstraction.
  2. Adobe Stock#243026154 What is DI? It is a technique whereby

    one object (or static method) supplies the dependencies of another object , instead of having it constructs them itself. Its responsible for: 1. Creating the objects 2. Knowing which classes require those objects 3. And provide them all those objects
  3. Why You Should Care? • Helps in Unit testing. •

    Boiler plate code is reduced, as initializing of dependencies is done by the injector component. • Extending the application becomes easier. • Helps to enable loose coupling between classes and its dependencies.
  4. Adobe Stock#243026154 DI Frameworks:Hilt • Koin generates code based on

    objects and functions, which can be used to inject dependencies. • uses a runtime approach to generate boilerplate code for dependency injection KOIN • Jetpack recommended library • Removes boilerplate code via annotations. -generates code based on annotations which can be used to inject dependencies. • uses a compile-time approach to generate boilerplate code for dependency injection.
  5. Adobe Stock#243026154 • Manage dependencies with a container class •

    Instances can be public or private • Add container class to the Application class for it to be available to whole application Manual DI