Skip to content

Instantly share code, notes, and snippets.

@klukwist
Created October 13, 2022 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klukwist/fbded34b97625b062228ab25ce112e68 to your computer and use it in GitHub Desktop.
Save klukwist/fbded34b97625b062228ab25ce112e68 to your computer and use it in GitHub Desktop.
sealed interface InstanceType<T> {
fun interface Factory<T> : InstanceType<T> {
fun build(): T
}
fun interface ParamFactory<T> : InstanceType<T> {
fun build(vararg params: Any): T
class Params {
var parameters: Array<out Any> = arrayOf()
private set
fun params(vararg parameters: Any) {
this.parameters = parameters
}
}
}
class Singleton<T>(private val factory: Factory<T>) : InstanceType<T> {
val instance: T by lazy {
factory.build()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment