When we want to create common class types, and need to configure those types without exposing that configuration logic to our client code, we can turn to the Factory design pattern. So let's see how this helps by learning more about this pattern.
Revisiting the Factory pattern in Kotlin
Understanding the Factory pattern
The factory design pattern is an object creation design pattern for creating objects with a shared type without exposing implementation details about how individual instances are configured. We've already seen an example of this pattern in Chapter 13, Kotlin on Android, when we wrote a Factory method for creating new Intent instances. Consider the following code snippet:
fun createIntent(context:...