The current DessertUiState stores individual primitive properties. I would like to suggest to store the complete Dessert object instead:
data class DessertUiState(
val revenue: Int = 0,
val dessertsSold: Int = 0,
val currentDessert: Dessert = Datasource.dessertList.first()
)
This follows Don't Repeat Yourself principle and reduces data duplication since Dessert already contains price, imageId, etc as then currentDessert becomes the singleSource of truth for dessert properties.
Current approach:
painter = painterResource(uiState.currentDessertImageId)
price = uiState.currentDessertPrice
My Suggested Approach:
painter = painterResource(uiState.currentDessert.imageId)
price = uiState.currentDessert.price
This would provide a better learning experience while demonstrating industry best practices.
The current DessertUiState stores individual primitive properties. I would like to suggest to store the complete Dessert object instead:
This follows Don't Repeat Yourself principle and reduces data duplication since Dessert already contains price, imageId, etc as then
currentDessertbecomes the singleSource of truth for dessert properties.Current approach:
My Suggested Approach:
This would provide a better learning experience while demonstrating industry best practices.