package com.example.dagger
import android.util.Log
import javax.inject.Inject
interface Battery{
fun getPower()
}
package com.example.dagger
import dagger.Binds
import dagger.Module
import dagger.Provides
@Module
abstract class NCBatteryModule {
@Binds
abstract fun bindsNCBattery(nickelCadmiumBattery: NickelCadmiumBattery):Battery
}package com.example.dagger
import android.util.Log
import javax.inject.Inject
class NickelCadmiumBattery @Inject constructor(): Battery {
override fun getPower() {
Log.i("MYTAG", " Power from NickelCadmiumBattery")
}
}package com.example.dagger
import android.util.Log
import javax.inject.Inject
class MemoryCard {
init {
Log.i("MYTAG", "Memory Card Constructed")
}
fun getSpaceAvailablity() {
Log.i("MYTAG", "Memory space available")
}
}package com.example.dagger
import dagger.Module
import dagger.Provides
@Module
class MemoryCardModule {
@Provides
fun providesMemoryCard(): MemoryCard {
return MemoryCard()
}
}
No comments:
Post a Comment