Leoboyean
08/21/2019, 10:31 PMmbonnin
08/21/2019, 10:33 PMobject Singleton {
}
Lou Morda
08/21/2019, 10:35 PMcompanion object
... "The companion object is a singleton, and its members can be accessed directly via the name of the containing class" https://kotlinlang.org/docs/tutorials/kotlin-for-py/objects-and-companion-objects.htmlLeoboyean
08/21/2019, 10:39 PMMark Murphy
08/21/2019, 10:47 PMobject Singleton
, you just refer to Singleton
. So, for example, if you had:
object Singleton {
fun doSomethingTrulyAwesome() {
TODO()
}
}
...then elsewhere you could just call SIngleton.doSomethingTrulyAwesome()
.
However, manual singletons (such as object
) are not very flexible, particularly when it comes to testing. You might want to look into "dependency inversion" options, such as Koin or Kodein, at some point.Paul N
08/22/2019, 8:58 AM