Table of contents
No headings in the article.
Low-level design (LLD) for a Splitwise application:
Database design: We will need to store information about users, their expenses, and any debts or credits between them. This will likely include tables for users, expenses, and debts/credits, with foreign keys to link them together.
User authentication and authorization: Users will need to be able to sign up for the application, log in, and log out. We will also need to implement measures to ensure the security of user accounts, such as password hashing and potentially two-factor authentication.
Expense tracking: The core functionality of the Splitwise application is the ability to track expenses and split them among users. This will likely involve creating forms for users to input their expenses, with fields for the amount, description, and any split information. We will also need to implement logic to calculate debts and credits between users based on the expenses they have entered.
Payment tracking: In addition to tracking expenses, we will also need to allow users to mark debts as paid, so that the application can accurately reflect the current state of debts between users.
User interface: Finally, we will need to design the user interface for the application, including the layout, navigation, and any necessary graphics or styling. This will involve creating wireframes and mockups, as well as implementing the front-end code to bring the design to life.
Here is an example of how the Splitwise application could be implemented in Java using object-oriented design principles:
public class Splitwise {
private List<User> users;
public Splitwise() {
users = new ArrayList<>();
}
public void addUser(User user) {
users.add(user);
}
public void addExpense(Expense expense) {
User payer = expense.getPayer();
payer.pay(expense.getAmount());
for (User user : expense.getSplitters()) {
user.receive(expense.getAmount() / expense.getSplitters().size());
}
}
public List<User> getUsers() {
return users;
}
}
public class User {
private String name;
private double balance;
public User(String name) {
this.name = name;
balance = 0;
}
public String getName() {
return name;
}
public double getBalance() {
return balance;
}
public void pay(double amount) {
balance -= amount;
}
public void receive(double amount) {
balance += amount;
}
}
public class Expense {
private User payer;
private List<User> splitters;
private double amount;
private String description;
public Expense(User payer, List<User> splitters, double amount, String description) {
this.payer = payer;
this.splitters = splitters;
this.amount = amount;
this.description = description;
}
public User getPayer() {
return payer;
}
public List<User> getSplitters() {
return splitters;
}
public double getAmount() {
return amount;
}
public String getDescription() {
return description;
}
}