Tag: kotlin
-
Real life Kotlin example of Delegation and Dependency Injection
Showcasing a simplified version of a real-life Kotlin application for order processing where we need to enhance functionality without touching the production code. Functional requirements Supposing the system already has the functionality for order creation, now the requirements are to implement: For simplicity, we will only log a message when saving to the database, auditing…
-
Never use the “else” branch in “when” expressions over an enum, sealed interface or sealed classes in Kotlin
When using when expressions over enum or sealed hierarchy (sealed interface or sealed class), the Kotlin compiler provides, by default, exhaustiveness checks. In other words, the compiler verifies that all possible values are handled in the when expression. Adding a new type RelaxingChair without handling the new value will result in a compilation error: The…
-
When and how to use extension functions
Technology has evolved like never before in the past two decades. It grows so much and so fast that we can hardly keep up with it. Look at how some older people struggle to understand new technology. For such people, technology brought a mess just by removing the buttons or the rotary dialer from phones…