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 ruleP1universalStack: Kotlin
clean-architectureseparation-of-concernskotlin
Keep UI-state types out of use cases and domain logic
A use case encapsulates business logic and must not depend on UI-layer types (snackbar/toast models, view state). Return a domain result (`Result<Domain, Error>`) and let the view model translate it into UI state. Mixing the layers couples business logic to the UI and blocks reuse/testing.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codekotlin
| 1 | class DownloadDocumentUseCase(...) { |
| 2 | suspend operator fun invoke(id: String): SnackbarInformation { ... } |
| 3 | } |
Explanation (EN)
The use case returns a UI-state object, coupling business logic to the presentation layer.
Objašnjenje (HR)
Good example
New codekotlin
| 1 | class DownloadDocumentUseCase(...) { |
| 2 | suspend operator fun invoke(id: String): Result<Document, DataError> { ... } |
| 3 | } |
| 4 | // ViewModel maps Result -> SnackbarInformation |
Explanation (EN)
The use case returns a domain Result; the view model owns UI-state mapping.
Objašnjenje (HR)