https://kotlinlang.org logo
Title
m

moizest89

04/26/2019, 3:49 PM
Hi!! I’ve tried to implement a Builder pattern design in Kotlin but on internet find a different ways to do. Does anyone have an idea the best way to implement one? 😬 Thanks!!!
t

tddmonkey

04/26/2019, 3:56 PM
To use in kotlin or from other JVM languages?
m

moizest89

04/26/2019, 3:58 PM
For use in Kotlin and Android
c

Casey Brooks

04/26/2019, 4:01 PM
Kotlin prefers the type-safe DSL-style builders to the traditional Java-style builders https://kotlinlang.org/docs/reference/type-safe-builders.html
m

moizest89

04/26/2019, 4:07 PM
??
t

tddmonkey

04/26/2019, 4:10 PM
It might be better to explain what you’re trying to achieve. The usual builder pattern isn’t usually required in kotlin due to defaults and named params
👆 7
c

Cody Engel

04/26/2019, 6:04 PM
Yeah default + named params are basically what the builder pattern does. I haven’t had a need for builders over the last 3ish years with Kotlin.
s

Shawn A

04/26/2019, 10:06 PM
They are useful for wrapping crappy java APIs. Like the aws SDK builders.
t

tddmonkey

04/27/2019, 6:25 PM
The SDK builders are the builder pattern! I found it more useful to do a full on DSL for the AWS SDK