Implementing Interfaces with Method Maps
Pairing with Duncan Pairing with Duncan
3.29K subscribers
709 views
38

 Published On Jul 19, 2024

Kent Beck has been writing recently on the idea of the adjacent possible and software design. The adjacent possible is the technological space that we can reach from where we are now in one hop - we don’t have to develop something intermediate before we can implement something useful.

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 https://github.com/dmcg/ktor-document...

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 (https://plugins.jetbrains.com/plugin/...) and then this gist https://gist.github.com/dmcg/1f56ac39...

If you like this video, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://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.

show more

Share/Embed