Implementing Interfaces with Method Maps
Published 2024-07-19
In software, sometimes we add some code and find ourselves expanding the adjacent possible. I think that happens in this episode. I was just adding the ability to discard coroutine continuation parameters when we call one interface through another, but on refactoring that code to remove duplication, I think that I have uncovered a technique that will allow us implement the decorator pattern for interfaces by populating maps of functions.
In this episode
* 00:00:48 Mapping from suspend to non-suspend functions
* 00:02:29 Add a test
* 00:04:00 It fails because we are looking for a method with a continuation
* 00:04:26 Duplicate our current implementation and fix it to find the right method to call
* 00:07:56 Now fix the invocation to discard the continuation
* 00:09:39 Now what is trying to get out of this mess - it's first-class functions
* 00:14:06 Now remove some duplication
* 00:16:40 Now retrofit our new plan to our old code
* 00:19:37 We can compose creating our map if we step back a bit
* 00:21:51 That opens up new possibilities
* 00:23:21 Review
The code for this video is on a GitHub fork github.com/dmcg/ktor-documentation
Other videos on proxies can be found in a Reflection playlist • Reflection
This video is in a playlist of Ktor episodes ( • Ktor ) and http4k ( • http4k )
I get lots of questions about the test progress bar. It was written by the inimitable @dmitrykandalov. To use it install his Liveplugin (plugins.jetbrains.com/plugin/7282-liveplugin) and then this gist gist.github.com/dmcg/1f56ac398ef033c6b62c82824a158…
If you like this video, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (java-to-kotlin.dev/). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.