Matias Reparaz
08/12/2019, 3:45 PMTimmy
08/13/2019, 11:04 AMMatias Reparaz
08/13/2019, 12:14 PMTimmy
08/13/2019, 2:38 PMval a = SomeImplementationOfServiceImpl2()
val b = SomeService(a)
// what I assume you want -> calls otherThing
b.something("test")
// what also works -> does not call otherThing
a.doSomething("test")(b)
Thinking about it more it definitely is an interesting approach to force users to use the SomeService class. However, I think I would still prefer just documenting it.Matias Reparaz
08/13/2019, 2:54 PMSameService
instance as argument, I assumed that kotlin will force the calling as the first example. This is because the java interop? Or I'm missing something about the kotlin receivers mechanism?Eric Martori
08/14/2019, 12:11 PMdoSomething
an extension function of SomeService
it can only be called in instances of the SomeService
.
interface ServiceImpl {
fun SomeService.doSomething(param: String): Int
}
You can still do:
val a = ServiceImpl()
val b = SomeService(a)
with(a) {
b.doSomething(test)
}
But is a lot harder the end user will end up doing this by accidentMatias Reparaz
08/14/2019, 12:58 PMclass SomeService(private val impl: ServiceImpl4) {
fun something(param: String): Int {
otherThing(param)
with(impl) {
return this@SomeService.doSomething(param)
}
}
private fun otherThing(param: String): Unit = TODO()
}
interface ServiceImpl4 {
fun SomeService.doSomething(param: String): Int
}
and the end user wouldn't notice. Thanks @Eric Martori, @Timmy what do you think about this option?Timmy
08/14/2019, 1:31 PMMatias Reparaz
08/14/2019, 1:44 PM