Wanna learn Builder Design Pattern Using Kotlin: <https://youtu.be/yqKfu5XSuBQ>
v
Wanna learn Builder Design Pattern Using Kotlin:

https://youtu.be/yqKfu5XSuBQ

🙌 1
e
I'll stick my chin out and say that a constructor with default and named parameters makes builder pattern redundant. Or make a DSL if your domain is too complex for a simple constructor. Builder pattern is an anti-pattern in Kotlin.
💯 6
v
Thoughtful
a
In general, I agree the builder pattern is redundant. However, ktor uses them in an interesting way to enable its DSL-esque structure.
Copy code
install(Authentication) {
    basic("auth-basic") {
        realm = "Access to the '/' path"
        validate { credentials ->
            if (credentials.name == "jetbrains" && credentials.password == "foobar") {
                UserIdPrincipal(credentials.name)
            } else {
                null
            }
        }
    }
}
Each of the assignment operations in
basic
is mutating the config, and then when the lambda ends, the config is used to construct the actual implementation. Interesting way to go about it.