Hello! I have a use case where I would like to shi...
# multiplatform
r
Hello! I have a use case where I would like to ship a library with
expect
declarations only in common main and have multiple
actual
different impl on each platform. For example 3 JVM modules that provide 3 different
actual
impls for the common main and same for other platforms like JS. The use case is that users may define programs over the common library but choose different runtime impl in
actual typealias F<A> = CustomImpl<A>
data types for a given expect class depending on how they want their programs to run. Essentially I’d like to push the responsibility to declare the
actual typealias
to the user and not be forced to provide an impl myself. Can this be accomplished with multiplatform modules? Any help is appreciated, I realise this is an odd case and potentially trying to abuse expect / actual for ad-hoc resolution. Thanks!
m
why dont you have this part of the actual implementation ? Like having a facade Impl per platform, based on a certain parameters (so runtime flow will control this) it will choose the right implementation among the 3 present.
r
I typically go with an
interface
rather than an
expect class
for this scenario.
same 3
r
@Mejdi @russhwolf thanks, I’ll give it some thought. I liked the fact that with actual / expect all abstract declarations in commonMain are like templates that get replaced by real types and not an inheritance relationship. I was able to provide some considerable polymorphic abstraction without the cost of double boxing on interfaces and classes just using the actual typealias.