Object-Oriented Design• Patterns: Strategy, Factory
Splitwise (Expense Sharing App)
Hard
Problem Summary
Design Splitwise to add expenses, share balances among friends, and optimize debt simplification.
Functional Scope
- Users can log group expenses split equally, unequally, or by percentages.
- Automatically compute balances between users.
- Provide a debt-simplification algorithm (minimize transactions between members).
Entity-Relationship (ER) Schema
Group [1] <---> [*] User Group [1] <---> [*] Expense Expense [1] <---> [*] Split User [1] <---> [1] BalanceSheet
Design Approach
Compute net balance sheets for all users. Run a greedy optimization algorithm (using a Min Heap for debtors and a Max Heap for creditors) to iteratively settle the largest debts, minimizing the total number of transactions.
Core Classes & Models
User (Name, Email, Balance Sheet)Expense (Base class for EqualExpense, UnequalExpense)Split (Maps User to split amount)Group (Tracks users and expenses list)
Code Blueprint
public abstract class Expense {
private double totalAmount;
public abstract boolean validate();
}