problemmediumoodobject-oriented-design-for-an-online-hotel-booking-system-oyo-likeobject oriented design for an online hotel booking system oyo likeobjectorienteddesignforanonlinehotelbookingsystemoyolikedesign-an-online-hotel-booking-system-like-oyo-roomsdesign an online hotel booking system like oyo roomsdesignanonlinehotelbookingsystemlikeoyorooms

Object-Oriented Design for Online Hotel Booking System (OYO-like)

MediumUpdated: Jan 1, 2026

Problem

Design an online hotel booking system (OYO-like) that lets users search hotels and book one or more rooms for a date range. Provide an object-oriented design that models hotels, rooms, bookings, users, and related enums/attributes.

Solution

1. Requirements Analysis

Functional requirements:

  • Search hotels by city and filters (room type, facilities, rating).
  • Book one or more rooms at a specific hotel for a date range.
  • Track booking status and payment state.
  • Represent hotel metadata (address, facilities) and room attributes (type, status).

Non-functional requirements:

  • Data consistency for bookings (prevent double-booking of the same room/time).
  • Reasonable performance for search and booking operations.
  • Extensible model to support extra facilities, pricing models, and promo codes.

Assumptions (derived from source):

  • Each booking is for rooms in a single hotel. Payments and billing are simplified to a PaymentStatus enum.

2. Use Case Diagram

Actors: User, System Administrator

Use case summary: User searches hotels, selects rooms, and completes a booking (including payment). Admin may manage hotels and rooms.

graph TB
        subgraph "Hotel Booking System"
                UC1["Search Hotels"]
                UC2["View Hotel Details"]
                UC3["Book Rooms"]
                UC4["View Bookings"]
        end
        User([User]) --> UC1
        User([User]) --> UC2
        User([User]) --> UC3
        User([User]) --> UC4
        Admin([Admin]) --> UC2
        style User fill:#4CAF50,color:#fff
        style Admin fill:#FF9800,color:#fff

3. Class Diagram

Core classes and responsibilities:

  • User: Holds user profile and contact details.
  • Hotel: Contains hotel metadata and list of rooms.
  • Room: Represents a single room with type, status, and identifier.
  • Booking: Captures booking details, booked rooms, amount, payment status and duration.
  • Address: Simple value object for hotel location.
  • Facilities: Value object wrapping a list of Facility enums.
classDiagram
    class User {
        +int userId
        +String name
        +String emailId
    }

    class Hotel {
        +int hotelId
        +String hotelName
        +Address address
        +List~Room~ rooms
        +float rating
        +Facilities facilities
    }

    class Room {
        +int roomId
        +int hotelId
        +RoomType roomType
        +RoomStatus roomStatus
    }

    class Booking {
        +int bookingId
        +int userId
        +int hotelId
        +List~Room~ bookedRooms
        +int amount
        +PaymentStatus paymentStatus
        +Duration duration
    }

    class Address {
        +String city
        +String pinCode
    }

        User "1" -- "0..*" Booking : "makes"
        Hotel "1" -- "1..*" Room : "has"
        Booking "1" -- "1..*" Room : "reserves"

4. Activity Diagrams

Activity: Search and Book

graph TB
        U[User searches hotels] --> S[System returns list of hotels]
        U --> V[User views hotel details]
        V --> B[User selects rooms and date range]
        B --> P[System checks availability]
        P --> C{Available?}
        C -- Yes --> R[Create Booking and collect payment]
        C -- No --> E[Show unavailable message]

Activity: Cancel Booking (simplified)

graph TB
        U[User requests cancel] --> S[System validates cancel policy]
        S --> A{Allowed?}
        A -- Yes --> R[Mark booking cancelled and refund if applicable]
        A -- No --> E[Return error]

5. High-Level Code Implementation

Below are cleaned Java skeletons (from the original note) and a Python equivalent. These are skeletons: attributes and method signatures only.

Java

public enum RoomStatus { EMPTY, NOT_EMPTY }
public enum RoomType { SINGLE, DOUBLE, TRIPLE }
public enum PaymentStatus { PAID, UNPAID }
public enum Facility { LIFT, POWER_BACKUP, HOT_WATER, BREAKFAST_FREE, SWIMMING_POOL }

public class User {
        int userId;
        String name;
        Date dateOfBirth;
        String mobile;
        String emailId;
}

public class Room {
        int roomId; // room number
        int hotelId;
        RoomType roomType;
        RoomStatus roomStatus;
}

public class Hotel {
        int hotelId;
        String hotelName;
        Address address;
        List<Room> rooms;
        float rating;
        Facilities facilities;
}

public class Booking {
        int bookingId;
        int userId;
        int hotelId;
        List<Room> bookedRooms;
        int amount;
        PaymentStatus paymentStatus;
        Date bookingTime;
        Duration duration;
}

public class Address { String city; String pinCode; String state; String streetNo; String landmark; }
public class Duration { Date from; Date to; }
public class Facilities { List<Facility> facilitiesList; }

Python

from __future__ import annotations
from dataclasses import dataclass, field
from enum import Enum
from typing import List
from datetime import datetime

class RoomStatus(Enum):
        EMPTY = 1
        NOT_EMPTY = 2

class RoomType(Enum):
        SINGLE = 1
        DOUBLE = 2
        TRIPLE = 3

class PaymentStatus(Enum):
        PAID = 1
        UNPAID = 2

class Facility(Enum):
        LIFT = 1
        POWER_BACKUP = 2
        HOT_WATER = 3
        BREAKFAST_FREE = 4
        SWIMMING_POOL = 5

@dataclass
class User:
        user_id: int
        name: str
        email: str

@dataclass
class Room:
        room_id: int
        hotel_id: int
        room_type: RoomType
        room_status: RoomStatus

@dataclass
class Booking:
        booking_id: int
        user_id: int
        hotel_id: int
        booked_rooms: List[Room]
        amount: int
        payment_status: PaymentStatus
        booking_time: datetime
        duration_from: datetime
        duration_to: datetime

Comments