Refactoring Closures to Classes in Kotlin

Опубликовано: 21 Октябрь 2022
на канале: Pairing with Duncan
869
34

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.


Смотрите видео Refactoring Closures to Classes in Kotlin онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 21 Октябрь 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 869 раз и оно понравилось 34 людям.