October 2019
Intermediate to advanced
434 pages
11h 54m
English
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: Context, id: String) = Intent(context, DetailsActivity::class.java).apply { putExtra(EXTRA_ID, id) }
In this example, details about how the Intent is actually created are hidden from the caller of createIntent(). Callers of that API only need to understand what arguments to pass in and that they will receive a properly ...
Read now
Unlock full access