Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
mobile ruleP1stack specificStack: kotlin
kotlinsealed-classstateexhaustiveness
Model finite UI/result states with a sealed class
Represent loading/success/error as a sealed hierarchy so the compiler enforces handling every state in when.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codekotlin
| 1 | data class UiState(val loading: Boolean, val data: X?, val error: String?) |
Explanation (EN)
Objašnjenje (HR)
Good example
New codekotlin
| 1 | sealed interface UiState { object Loading; data class Ok(val x: X); data class Err(val m: String) } |
Explanation (EN)
Objašnjenje (HR)