Closures are a functional way of information hiding, but today we find ourselves hiding too much information about how our application is configured, so that we can't reuse the logic in our tests.
In contrast to closures, classes can selectively hide or publish information. By converting our configuration code from a closure to a class we are able to access the results of the configuration logic, and also have a convenient place to host other functionality, like starting up a server.
In the second half of the episode there is a rather interesting transform that converts a constructor into a static function in order to all us to invert the dependency between two classes.
This is Part 49(!) of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist
• All Gilded Rose Episodes
and the code on GitHub
https://github.com/dmcg/gilded-rose-tdd
If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook
http://java-to-kotlin.dev. Chapter 19 covers error handling.
Watch video Refactoring Closures to Classes in Kotlin online without registration, duration hours minute second in high quality. This video was added by user Pairing with Duncan 21 October 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 869 once and liked it 34 people.