Created
October 13, 2022 14:33
-
-
Save klukwist/fbded34b97625b062228ab25ce112e68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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