Question: 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?

Answer: 
Unfortunately, there is no way to enforce that only objects (singletons in Kotlin) can inherit from a certain abstract/open class or interface in Kotlin. `object` declaration is just syntactic sugar for a regular class with a Singleton pattern.

I know it's not much, but I guess you can achieve this to a certain degree by adding documentation, asking users to implement this class by Singletons alone.

By the way, I would use an interface instead of an abstract class for this purpose.
Instead of creating abstract class just change the code like this:-

```
object SingletonConnection{
     fun start(){ /* code */ }
     fun connect(){ /* code */ }
     fun clientLogic()   
}

```

It will provide the same implementation which you want to achieve using abstract class.

Also get the method using this code:-

```
SingletonConnection.start()

```