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
data class Cart( | |
val products: List<Product> | |
) |
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
class CartInteractor( | |
private val cartRepository: CartRepository | |
) { | |
fun getCart() : Cart { | |
return cartRepository.getCart() | |
} | |
} |
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
class CartViewModel( | |
private val cartInteractor: CartInteractor | |
): ViewModel() { | |
private val approximatePriceOfProductsLiveData = MutableLiveData<String>() | |
init { | |
val cart = cartInteractor.getCart() | |
val approximatePriceOfProducts : BigDecimal = TODO("Must be calculated") | |
val approximatePriceOfProductsLiveData = approximatePriceOfProducts.toString() |
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
data class Cart( | |
val products: List<Product> | |
) { | |
val productsApproximatePrice : BigDecimal | |
get() = products.sumOf { it.price } | |
} |
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
class CartInteractor( | |
private val cartRepository: CartRepository | |
) { | |
fun getCart() : Cart { | |
return cartRepository.getCart() | |
} | |
fun getApproximatePriceOfProducts(cart: Cart): BigDecimal { | |
return cart.products.sumOf{ it.price } |
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
class AnotherInteractor( | |
private val cartInteractor: CartInteractor, | |
private val anotherRepository: AnotherRepository | |
){ | |
fun doSomething() { | |
val cart = cartInteractor.getCart() | |
anotherRepository.doSomething(cart.productsApproximatePrice) | |
// Rest of the code | |
} |
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
data class Product( | |
val title: String, | |
val price: BigDecimal, | |
val discount: BigDecimal // Value from 0.00% to 1.00% | |
) | |
data class Wishlist( | |
val products: List<Product> | |
){ | |
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
data class Product( | |
val title: String, | |
val price: BigDecimal, | |
val discount: BigDecimal // Value from 0.00% to 1.00% | |
){ | |
val productPriceWithDiscount : BigDecimal | |
get() { | |
val discount = price * discount | |
return price - discount |
OlderNewer