DEV Community

Discussion on: Gang of Four Patterns in Kotlin

Collapse
 
sorokod profile image
David Soroko

Using apply for post constructor changes is nice but I wouldn't call it a builder. With the approach you are describing an instance is created first, with empty constructor, and then modified in the apply{} block. This means that

  1. Default values are required

  2. It is not possible to ensure that an instance exists only if the parameters are valid