Francis Mariano
07/10/2024, 6:27 PMFrancis Mariano
07/10/2024, 6:29 PMinterface HardwareType<T>
interface PeripheralType<T> {
val peripheral: Peripheral
val type: HardwareType<T>
}
interface PeripheralRepository<T> {
val peripherals: StateFlow<Map<String, PeripheralType<T>>>
}
object PeripheralRepositoryImpl : PeripheralRepository <T> {
override val peripherals: StateFlow<Map<String, PeripheralType<T>>>
get() = TODO("Not yet implemented")
}
The repository is a object and one object can not has generics type. The HardwareType depends on client is consuming the library.Francis Mariano
07/10/2024, 6:31 PMJoffrey
07/10/2024, 6:41 PMclass
instead of an object
?Francis Mariano
07/10/2024, 6:47 PMclass
I will have to use a framework of injection or creating the repository in high level of the application and distributing to all the classes that use it.
I think the second approach is coherent.Joffrey
07/10/2024, 6:51 PMval mySpecificRepo by lazy { PeripheralRepositoryImpl<SpecificT>() }
Francis Mariano
07/10/2024, 7:00 PMby lazy
in the consumers (different classes) I get the same reference of object? I did not know about that.Francis Mariano
07/10/2024, 8:06 PMby lazy
do not guarantee the same reference of objectJoffrey
07/10/2024, 8:38 PMFrancis Mariano
07/10/2024, 8:53 PMJoffrey
07/10/2024, 10:51 PMobject
before, that you declared once and used in different places. Similarly, you could declare a top-level property initialized lazily once, and use it everywhereJoffrey
07/10/2024, 10:53 PMFrancis Mariano
07/11/2024, 3:27 PMFrancis Mariano
07/11/2024, 3:27 PM