Singleton
Singleton – the most popular bachelor in town. Everybody knows him, everybody talks about him, and everybody knows where to look for him.
Even people who don't like using design patterns will know Singleton by name. At one point, it was even proclaimed an anti-pattern, but only because of its wide popularity.
So, for those who are encountering it for the first time, what is this design pattern all about?
Usually, if you have a class, you can create as many instances of it as you want. For example, let's say that we both 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...