Created
March 9, 2023 09:10
-
-
Save svsq/bdebf1e1ac805e318cbdcbc7f3541040 to your computer and use it in GitHub Desktop.
Example of sealed class for managing an API response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class NetworkResponse<T>( | |
val data: T? = null, | |
val message: String? = null | |
) { | |
class Success<T>(data: T) : NetworkResponse<T>(data) | |
class Error<T>(message: String?, data: T? = null) : NetworkResponse<T>(data, message) | |
class Loading<T> : NetworkResponse<T>() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment