I am implementing a library following a template method design pattern. It involves creating costly IO connection. To avoid any resource leaks, i want to enforce singleton instance on abstract class level. client just need to override the method which involves logic.
how can i do with kotlin?
abstract class SingletonConnection{
fun start(){ /* code */ }
fun connect(){ /* code */ }
abstract fun clientLogic()
}
If class A extends this, it should be singleton class. not allowed to initialise multiple times. how to do in kotlin?