The idea is simple and not new; use a single project to build an application targeting both mobile, web and backend. The innovative part is sharing as much of the code as possible, instead of generating code for each platform. A lot of the logic is shared between platforms and the user interface is build natively. Developers build the application views like the are used to in iOS and android, but fill the views using shared logic. The philosophy is; let Xcode and Android Studios do what they are good at, but write the underlying code just once.
Business logic can be shared by different frontend applications. Models and validators for example can also be shared with the backend. No more inconsistencies between the back- and frontend! Refactors are also made easy, by refactoring all applications simultaneously automatically.
Different common modules are used to share code between the different platforms. Special libraries can be used, offering the same functionality for all available platforms. Those libraries add extra functionality, like we are used to, with the addition of working the same on all platforms. Because of this, the library can be called from common code without problems and no differences between the platforms they are run on!
It's even possible to use a comparable way to call platform specific code from common code. An example use case is to send a push message from common code. The implementation of a push message is different on Android and iOS. Using a construction called an 'expected' class, this can still be realized. An expected class is like an interface; it has a definition of a class and its functions. Every platform needs to have an 'actual' implementation of the expected class; like the implementation of an interface. When executing the common code, the platform specific code is called. In this case to send a push message whether the code is run on Android or iOS.
That sounds good right?My enthusiasm is high because of the following advantages:
- Write code just once for backend and frontend
- No inconsistencies between models
- Easy refactors
- Easy to add another platform
- Apps are native and so is the feeling
At this moment the above is only a vision of how Jetbrains wants multiplatform to work. The technology is in its infancy and for the time being is only used in two applications in practice. (The KotlinConf app and the Kotlin Academy, a website/app with blogs about Kotlin). My experience so far: getting an application up-and-running is a lot of trouble. The experimental status is very noticeable: the documentation and examples are often outdated and are very limited. Standard libraries don't always function well and experimental dependencies could break at any time when they are updated.
In the future multiplatform will hopefully develop as a production ready product. To achieve this multiplatform needs a stable core of libraries and more Kotlin JS frameworks. Right now React has a lot of potential! My recommendation is to not use multiplatform in practice in the near future, but definitely try it out and play with it!
ReferencesHarris, Richard.why-kotlin-language-use-is-skyrocketing, Appdevelopermagazine
ImagesRozov, Kirill. Sharing code between platforms
Moskala, Marcin. Multiplatform native development in Kotlin. Now with iOS! Kotlin AcademySo how does that work?