Which design approach best supports scalability and clear responsibility?
hard📝 Trade-off Q15 of 15
LLD - Design — Splitwise (Expense Sharing)
You want to design a system where multiple users in a group can add expenses, and the system automatically calculates how much each user owes or is owed. Which design approach best supports scalability and clear responsibility?
AMake User class handle all expense calculations and group management to centralize logic
BUse only a single Expense class that stores all users and groups inside it to simplify design
CCreate User, Group, and Expense classes where Group manages users and expenses; Expense tracks amount and split; User tracks individual balances updated by Group
DStore all data in a flat file and calculate splits manually each time without classes
Step-by-Step Solution
Solution:
Step 1: Identify responsibilities for each class
User holds personal info and balances, Group manages users and expenses, Expense tracks costs and splits.
Step 2: Evaluate design for scalability and clarity
Create User, Group, and Expense classes where Group manages users and expenses; Expense tracks amount and split; User tracks individual balances updated by Group cleanly separates concerns, making it easier to maintain and scale.
Final Answer:
Create User, Group, and Expense classes where Group manages users and expenses; Expense tracks amount and split; User tracks individual balances updated by Group -> Option C