...

/

Singleton Design Pattern

Singleton Design Pattern

Learn the singleton design pattern and its implementation in Kotlin.

We'll cover the following...

Singleton—even people who don’t like using design patterns will know the singleton pattern by name. At one point, it was even proclaimed an anti-pattern, but only because of its wide popularity.

Press + to interact
The Singleton design pattern
The Singleton design pattern

So, for those who are encountering it for the first time, what is this design pattern all about?

Usually, if we have a class, we can create as many instances of it as we want. For example, let’s say that we are asked to list all of our favorite movies:

val myFavoriteMovies = listOf("Black Hawk Down", "Blade Runner")
val yourFavoriteMovies = listOf(...)

Note that we can create as many instances of List as we want, and there’s no problem with that. Most classes can have multiple instances.

Next, what if we both want to list the best movies in the Quick and Angry series?

val myFavoriteQuickAndAngryMovies = listOf()
val yourFavoriteQuickAndAngryMovies = listOf()

Note that these two ...