u/dmcgin r/Kotlin • Recommends
Kotlin Refactoring - Introducing Types to Simplify Logic
#kotlin#refactoring#valueclasses
4.5K subscribers • 13 videos on Hallway
Intermediate. Assumes working knowledge.
1.1K views4 years ago1 recommendation
Programming languagesSoftware designKotlinRefactoring and legacy codeDesign patterns
Duncan McGregor refactors a Kotlin codebase to introduce a new value class, simplifying domain logic and class responsibilities.
Often just moving where code lives can simplify our software, and refactoring to introduce a new type can allow everything to relax into place. We were using NonNegativeInt to represent our domain concept of Quality, but that leads to complication in our Item class, which has to deal with odd requirements until we introduce a new Value Class to make everything much simpler. This is Part 34 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 youtube.com/playlist?list=PL1ssMPpyqociJNwykAOB9_KEZVW7BW7m2 and the code on GitHub github.com/dmcg/gilded-rose-tdd This sub-series on Value Classes is also a playlist youtube.com/playlist?list=PL1ssMPpyqocgOPGnbadMACwJl-PT0C_Od If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook java-to-kotlin.dev. Chapter 19 covers error handling.What people say. Recommended as a great example of refactoring to domain-specific types in Kotlin.
u/dmcgin r/Kotlin • Recommends