mbonnin
11/08/2021, 11:24 AM// MyClass is platform-specific
expect class MyClass(
param1: Param1,
param2: Param2,
param3: Param3
) {
// Builder is the same for all platforms
class Builder {
var param1: Param1? = null
// ...
fun build(): MyClass {
return MyClass(
param1 = param1 ?: defaultParam1,
// ...
)
}
ย }
}
russhwolf
11/08/2021, 1:20 PMMyClass
an interface and doing a expect fun MyClass(...): MyClass
that returns platform-specific implementations.mbonnin
11/08/2021, 1:27 PMmbonnin
11/08/2021, 1:28 PMBuilders
but given that my example had only 2 parameters, that'll work nicely ๐russhwolf
11/08/2021, 1:28 PMBuilder
inside the interfacembonnin
11/08/2021, 1:29 PMrusshwolf
11/08/2021, 1:29 PMrusshwolf
11/08/2021, 1:30 PMexpect class
)mbonnin
11/08/2021, 1:32 PMBuilders
everywhere now ๐
so it's more consistent to leave it there toombonnin
11/08/2021, 1:32 PMmbonnin
11/08/2021, 1:33 PMBuilders
for multiplatform classes