Effective Kotlin: Item 2 — Consider a builder when faced with many constructor parameters

The Builder pattern is promoted in Effective Java to help work around the telescoping constructor anti-pattern when you end up with numerous constructors due to optional parameters. See Joshua’s book for the pros and cons of using the Builder pattern.

We see the pattern loosely in use in Java’s StringBuilder. In Android the AlertDialog.Builder() is a more traditional implementation. IntelliJ also provides the built-in Replace Constructor with Builder refactoring to help implement…