Skip to content

Improve UiState design by storing whole Dessert object instead of primitive properties #55

@jkasper12

Description

@jkasper12

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions