Posts

Showing posts with the label Hilt

Dagger-Hilt in Android

Image
Overview Class without dependency injection: class Mobile { private var battery : Battery? = null private var processor : Processor? = null init { battery = Battery() processor = Processor() } } In the above line of code, when you create an object of a Mobile, then its constructor will have to create the object of Battery and Processor to initialize the properties of Mobile. Henceforth, it has to violate the principle defined by "Uncle Bob" i.e. 1st principle of Solid Principle (Single responsibility Principle).  In addition, we have to admit that whenever we are creating an object of Mobile, the class will create an object of Battery and Processor. In future, if we want to pass the object of Battery in the class then we are not allowed to do it because of scope limitation.  What is dependency injection? When an object of a class depends on the object of another classes that is dependency injection. class Mobile( var battery : Battery? ...