Singleton
The Singleton pattern is widely recognized and often referred to, even by those who are not fans of using design patterns.
At one point, the Singleton pattern was considered an “anti-pattern” precisely because of its overwhelming popularity. The logic was this: if something is everywhere, it can’t be that good. In the Spring Framework, the Singleton scope is indeed the default for its components, which are commonly referred to as “beans.” This approach is similarly adopted in the Koin framework, illustrating the widespread acceptance and use of the Singleton scope in modern software development.
For those encountering this pattern for the first time, let’s explore what it’s all about. In the previous chapter, we already discussed classes and data structures in Kotlin.
Typically, when you have a class, you can create multiple instances of it. For instance, imagine we are both asked to list our favorite movies.
...