Skip to content

Instantly share code, notes, and snippets.

View 5AbhishekSaxena's full-sized avatar
Tryin'

Abhishek Saxena 5AbhishekSaxena

Tryin'
View GitHub Profile
sealed class UiImage<out T>(val resource: T) {
data class LocalImage(private val imageRes: Int) : UiImage<Int>(resource = imageRes)
data class RemoteImage(private val imageUrl: String) : UiImage<String>(resource = imageUrl)
}
@5AbhishekSaxena
5AbhishekSaxena / UiImage.kt
Last active April 19, 2022 19:08
UiImage using Sealed Classes
sealed class UiImage {
data class LocalImage(val imageRes: Int) : UiImage()
data class RemoteImage(val imageUrl: String) : UiImage()
}
@5AbhishekSaxena
5AbhishekSaxena / ArticleListViewModelRobot.kt
Last active September 30, 2021 04:00
Test Robot with Execute around example
class ArticleListViewModelRobot private constructor() {
private lateinit var viewModel: ArticleListViewModel
private val fakeRepository = FakeArticleRepository()
private fun setup() {
buildViewModel()
}
fun buildViewModel() = apply {
@5AbhishekSaxena
5AbhishekSaxena / DiDriver.kt
Created April 25, 2021 12:11
Design pattern used to implement IoC. It allows creating the dependent objects outside of the class and provides those objects in different ways.
fun main() {
val redSauce = RedSauce()
val whiteSauce = WhiteSauce()
val greenSauce = GreenSauce()
val redSaucePasta = Pasta(redSauce)
println(redSaucePasta.getPasta())
val whiteSaucePasta = Pasta(whiteSauce)