```// 1 interface FooFactory { fun getFoo(): F...
# codereview
a
Copy code
// 1
interface FooFactory {
    fun getFoo(): Foo
}

// 2
interface FooFactory : () -> Foo

// 3
interface FooFactory : () -> Foo {
    override fun invoke(): Foo
}
Is 2 or 3 something that people do? (not using a
typealias
here, because it wouldn't work with Dagger)
1️⃣ 4
2️⃣ 1
3️⃣ 1
m
I think 1️⃣ would be the preferred from a domain-modeling standpoint, while the other two only express a generic function intent. In this particular case maybe they won’t be bad since the interface name already conveys the meaning and a function name will probably be redundant. This said and considering Dagger constraint, maybe I’d prefer 2️⃣ for conciseness.
a
One issue with 2️⃣ that I see is that you can't look for invocations using "find usages" in IDE
m
You can also look out for Kotlin 1.4 release where they plan to introduce the functional interface which would probably be the prefered solution for your situation once it releases. https://blog.jetbrains.com/kotlin/2019/12/what-to-expect-in-kotlin-1-4-and-beyond/
👍 1