Sealed Classes, Unsealed Complexity
summary
Demonstrates that Kotlin sealed classes replace fragile enums and ad‑hoc error handling by modeling concrete outcomes: a login API is refactored into LoginSuccess/LoginFailure wrappers, enums fail because they cannot carry state, and sealed classes carry tokens, messages or exceptions and enable exhaustive when checks at compile time. A second example replaces duplicated search/refresh UI code with a sealed SearchViewState so states become mutually exclusive view states, reducing bugs, duplication and feedback cycles.
AI-written summary · about
chapters (5)
- 0:00Start
- 14:11Disadvantages of Enums
- 14:35Scaled classes
- 18:06Advantages of Sealed classes
- 32:24Overview
related talks
41mLeveraging Sealed Classes in Kotlin
34mSealed Classes Opened My Mind: How We Use Kotlin to Tame State at Etsy
42mDissecting Kotlin: Unsealing the Sealed, the SAM, and Other Syntax
37mHow Kotlin Lets Us Remove Exceptions from Our Code
43mRepresenting State: the Kotlin Edition
43mFrom Effective Java to Effective Kotlin
01h 03mHow Kotlin makes your Java code better
41mSafe Kolin
