Design (LLD) a Restaurant Management system - Machine Coding

Design (LLD) a Restaurant Management system - Machine Coding

Restaurant-Management-System.webp

Restaurant Management system

A Restaurant Management System is a software built to handle all restaurant activities in an easy and safe manner. This System will give the Restaurant management power and flexibility to manage the entire system from a single portal. The system allows the manager to keep track of available tables in the system as well as the reservation of tables and bill generation.

Features

We will focus on the following set of requirements while designing the Restaurant Management System:

  1. The restaurant will have different branches.

  2. Each restaurant branch will have a menu.

  3. The menu will have different menu sections, containing different menu items.

  4. The waiter should be able to create an order for a table and add meals for each seat.

  5. Each meal can have multiple meal items. Each meal item corresponds to a menu item.

  6. The system should be able to retrieve information about tables currently available to seat walk-in customers.

  7. The system should support the reservation of tables.

  8. The receptionist should be able to search for available tables by date/time and reserve a table.

  9. The system should allow customers to cancel their reservation.

  10. The system should be able to send notifications whenever the reservation time is approaching.

  11. The customers should be able to pay their bills through credit card, check or cash.

  12. Each restaurant branch can have multiple seating arrangements of tables.

Rough Solution (LLD-Machine Coding)

// Enums representing various statuses in the restaurant management system

public enum ReservationStatus {
    REQUESTED, PENDING, CONFIRMED, CHECKED_IN, CANCELED, ABANDONED
}

public enum SeatType {
    REGULAR, KID, ACCESSIBLE, OTHER
}

public enum OrderStatus {
    RECEIVED, PREPARING, COMPLETED, CANCELED, NONE
}

public enum TableStatus {
    FREE, RESERVED, OCCUPIED, MAINTENANCE, OTHER
}

public enum AccountStatus {
    ACTIVE, CLOSED, CANCELED, BLACKLISTED, BLOCKED
}

public enum PaymentStatus {
    UNPAID, PENDING, COMPLETED, FAILED, DECLINED, CANCELLED, ABANDONED, SETTLING, SETTLED, REFUNDED
}

// Supporting Address class
public class Address {
    private String streetAddress;
    private String city;
    private String state;
    private String zipCode;
    private String country;

    // Constructors, getters, and setters are omitted for brevity
}

// Abstract class for Person, common attributes for all types of people involved
public abstract class Person {
    private String name;
    private String email;
    private String phone;

    // Constructor and methods omitted for brevity
}

// Abstract Employee class extending Person
public abstract class Employee extends Person {
    private int employeeID;
    private Date dateJoined;
    private Account account;

    // Constructor and methods omitted for brevity
}

// Concrete Receptionist class
public class Receptionist extends Employee {
    public boolean createReservation(Reservation reservation) {
        System.out.println("Reservation created successfully.");
        return true;
    }

    public List<Customer> searchCustomer(String name) {
        // Search logic
        return new ArrayList<>();
    }
}

// Concrete Manager class
public class Manager extends Employee {
    public boolean addEmployee(Employee employee) {
        System.out.println("Employee added successfully.");
        return true;
    }

    public boolean modifyMenu(Menu menu) {
        System.out.println("Menu modified successfully.");
        return true;
    }
}

// Chef class for processing orders
public class Chef extends Employee {
    public boolean takeOrder(Order order) {
        System.out.println("Chef received order: " + order.getOrderID());
        return true;
    }
}

// Cashier class for processing payments
public class Cashier extends Employee {
    public boolean generateCheck(Order order) {
        System.out.println("Check generated for order: " + order.getOrderID());
        return true;
    }

    public boolean processPayment(Check check) {
        System.out.println("Payment processed for check: " + check.getCheckID());
        return true;
    }
}

// Notification system using the Observer Pattern
interface Observer {
    void update(String message);
}

class Customer implements Observer {
    private String name;
    private Account account;

    public Customer(String name, Account account) {
        this.name = name;
        this.account = account;
    }

    @Override
    public void update(String message) {
        System.out.println("Notification for customer " + name + ": " + message);
    }
}

// SystemNotifier to send notifications to customers
class SystemNotifier {
    private List<Observer> observers = new ArrayList<>();

    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    public void notifyObservers(String message) {
        for (Observer observer : observers) {
            observer.update(message);
        }
    }
}

// Table-related classes
public class Table {
    private int tableID;
    private TableStatus status;
    private int maxCapacity;
    private List<TableSeat> seats;

    public boolean isTableFree() {
        return status == TableStatus.FREE;
    }

    public boolean addReservation(Reservation reservation) {
        this.status = TableStatus.RESERVED;
        System.out.println("Table reserved.");
        return true;
    }

    public static List<Table> search(int capacity, Date startTime) {
        // Search for tables based on capacity and availability
        return new ArrayList<>();
    }
}

public class TableSeat {
    private int seatNumber;
    private SeatType type;

    public boolean updateSeatType(SeatType type) {
        this.type = type;
        return true;
    }
}

// Reservation class
public class Reservation {
    private int reservationID;
    private Date reservationTime;
    private int peopleCount;
    private ReservationStatus status;
    private Table table;
    private Customer customer;
    private List<Notification> notifications;

    public boolean updatePeopleCount(int count) {
        this.peopleCount = count;
        System.out.println("People count updated.");
        return true;
    }
}

// Menu-related classes
public class MenuItem {
    private int menuItemID;
    private String title;
    private String description;
    private double price;

    public boolean updatePrice(double price) {
        this.price = price;
        System.out.println("Menu item price updated.");
        return true;
    }
}

public class MenuSection {
    private int sectionID;
    private String title;
    private List<MenuItem> menuItems;

    public boolean addMenuItem(MenuItem menuItem) {
        menuItems.add(menuItem);
        return true;
    }
}

public class Menu {
    private int menuID;
    private String title;
    private List<MenuSection> menuSections;

    public boolean addMenuSection(MenuSection section) {
        menuSections.add(section);
        return true;
    }
}

// Order-related classes
public class MealItem {
    private int mealItemID;
    private int quantity;
    private MenuItem menuItem;

    public boolean updateQuantity(int quantity) {
        this.quantity = quantity;
        return true;
    }
}

public class Meal {
    private int mealID;
    private TableSeat seat;
    private List<MealItem> mealItems;

    public boolean addMealItem(MealItem item) {
        mealItems.add(item);
        return true;
    }
}

public class Order {
    private int orderID;
    private OrderStatus status;
    private Date creationTime;
    private Meal[] meals;
    private Table table;
    private Check check;
    private Waiter waiter;
    private Chef chef;

    public int getOrderID() {
        return orderID;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
        System.out.println("Order status updated to: " + status);
    }

    public boolean addMeal(Meal meal) {
        System.out.println("Meal added to order.");
        return true;
    }

    public boolean removeMeal(Meal meal) {
        System.out.println("Meal removed from order.");
        return true;
    }
}

// Check class for processing payments
public class Check {
    private int checkID;
    private PaymentStatus status;
    private double amount;

    public int getCheckID() {
        return checkID;
    }

    public boolean processPayment() {
        System.out.println("Payment processed for check: " + checkID);
        return true;
    }
}

// Command Pattern for creating orders
interface Command {
    void execute();
}

class CreateOrderCommand implements Command {
    private Order order;

    public CreateOrderCommand(Order order) {
        this.order = order;
    }

    @Override
    public void execute() {
        System.out.println("Order created with ID: " + order.getOrderID());
    }
}

// Example Main class demonstrating the usage of Observer, Command, and other patterns
public class Main {
    public static void main(String[] args) {
        // Create SystemNotifier and customers
        SystemNotifier notifier = new SystemNotifier();
        Customer alice = new Customer("Alice", new Account());
        Customer bob = new Customer("Bob", new Account());
        notifier.addObserver(alice);
        notifier.addObserver(bob);

        // Notify customers about table reservation
        notifier.notifyObservers("Table reservation confirmed!");

        // Create an order using the Command pattern
        Order order = new Order();
        order.setStatus(OrderStatus.RECEIVED);
        Command createOrder = new CreateOrderCommand(order);
        createOrder.execute();

        // Process a payment using Cashier
        Cashier cashier = new Cashier();
        Check check = new Check();
        cashier.processPayment(check);
    }
}

Did you find this article valuable?

Support Subhahu Jain by becoming a sponsor. Any amount is appreciated!