j

    Joost Klitsie

    1 year ago
    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
    external
    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?
    russhwolf

    russhwolf

    1 year ago
    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.