Pick the fix
Two ViewModels each combine the cart, the user's tier and promotions to compute a total, and they disagree. What's the best fix?
Hint 1 of 1
Where should logic shared by screens live?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Move the calculation into a CalculateCartTotalUseCase both ViewModels use
Correct. Shared business logic in one place stops the drift.
Why not the others?
- B Copy the more correct version into both. Still duplicated.
- C Put the logic in the composable. Logic in UI is harder to test and still duplicated.
- D Put it in a base ViewModel. Inheritance for shared logic couples unrelated screens.