Joost Klitsie

03/21/2021, 10:38 AM
What is the common census on the topic expect/actual vs using interfaces? In my KMP project I do use expect actual, but only where I have to (basically it is a workaround for my props interface, which need to be
on my JS project and that doesn't fly for the other platforms, so there I expect/actual the interface). All the rest is simply an interface with implementations on different platforms and my dependency injection wiring it up. Are there guidelines for this?


03/21/2021, 4:45 PM
They both have their pluses and minuses, depending on your needs. expect/actual can do things that interfaces can’t, like constructors and top-level properties and functions. But you can only have a single implementation with expect/actual, so if you want to be able to swap out a test double then interfaces are better. I tend to expect/actual configuration-level stuff and some utilities, and use interfaces otherwise.