I have a manager class that has an Android and iOS impl (from a 3rd party lib). "ex. MyManagerImpl()". To construct the 3rd party manager, iOS does not require a Context but Android does. I created a common class "MyManager" which pulls out all the common methods needed to be called within commonMain.
//commonMain
expect class MyManager {
fun method1()
companion object Factory {
makeManager(): MyManager
}
}
val manager = MyManager.Factory.makeManager() // ex intended usage
//androidMain
MyManagerImpl(context: Context) {
fun method1()
}
actual class MyManager private constructor(manager: MyManagerImpl) {
..
actual companion object Factory {
override fun makeManager(): MyManager {
return MyManager(MyManagerImpl(?how to get context?))
}
}
}
//iosMain
MyManagerImpl() {
fun method1()
}
actual class MyManager private constructor(manager: MyManagerImpl) {
..
actual companion object Factory {
override fun makeManager(): MyManager {
return MyManager(MyManagerImpl())
}
}
}
What is the cleanest way to merge the two implementations? Is it possible to do so even tho they have different constructor dependencies? We would like to be able to construct the classes lazily within commonMain. Is this possible?