Skip to content

Instantly share code, notes, and snippets.

@kuntalchandra
Last active August 9, 2024 03:36
Show Gist options
  • Save kuntalchandra/f8260dee9bf3e8c0084ce8c31fe3554e to your computer and use it in GitHub Desktop.
Save kuntalchandra/f8260dee9bf3e8c0084ce8c31fe3554e to your computer and use it in GitHub Desktop.
Mock LLD of Hotel Management
from abc import ABCMeta, abstractmethod
from enum import Enum
from typing import List, Optional
# Enum Definitions
RoomStyle = Enum("RoomStyle", "STANDARD DELUX SUITE")
RoomStatus = Enum("RoomStatus", "AVAILABLE RESERVED NOT_AVAILABLE OCCUPIED SERVICE_IN_PROGRESS")
BookingStatus = Enum("BookingStatus", "PENDING CONFIRMED CANCELED")
# Class Definitions
class Hotel(object):
def __init__(self):
self._name = None
self._id = 0
self._location = Location()
self._rooms = []
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
@property
def id(self):
return self._id
@id.setter
def id(self, value):
self._id = value
class Location(object):
def __init__(self):
self._pin = 0
self._street = None
self._area = None
self._city = None
self._country = None
class Room(object):
def __init__(self):
self._room_number = None
self._room_style = RoomStyle.STANDARD
self._room_status = RoomStatus.AVAILABLE
self._booking_price = 0.0
self._room_keys = []
self._house_keeping_logs = []
class RoomKey(object):
def __init__(self):
self._key_id = None
self._bar_code = None
self._issued_at = None
self._is_active = True
self._is_master = False
def assign_room(self, room: Room) -> None:
pass
class RoomBooking(object):
def __init__(self):
self._booking_id = None
self._start_date = None
self._duration_in_days = 0
self._booking_status = BookingStatus.PENDING
self._guest_list = []
self._room_info = []
self._total_room_charges = BaseRoomCharge()
class HouseKeepingLog(object):
def __init__(self):
self._description = None
self._start_date = None
self._duration = 0
self._house_keeper = HouseKeeper()
def add_room(self, room: Room) -> None:
pass
class Person(metaclass=ABCMeta):
def __init__(self):
self.name = None
self.phone = None
self.account_detail = Account()
class HouseKeeper(Person):
def __init__(self):
super().__init__()
def get_rooms_serviced(self, date: Optional[str] = None) -> List[Room]:
pass
# composition is illustrated below
class Guest(Person):
def __init__(self):
super().__init__()
self._search = Search()
self._booking = Booking()
def get_all_room_bookings(self) -> List[RoomBooking]:
pass
class Receptionist(Person):
def __init__(self):
super().__init__()
self._search = Search()
self._booking = Booking()
def check_in_guest(self, guest: Guest, booking_info: RoomBooking):
pass
def check_out_guest(self, guest: Guest, booking_info: RoomBooking):
pass
class Admin(Person):
def __init__(self):
super().__init__()
def add_room(self, room_detail: Room) -> None:
pass
def delete_room(self, room_id: int) -> Room:
pass
def edit_room(self, room_detail: Room) -> None:
pass
class Account(object):
def __init__(self):
self._username = None
self._password = None
self._account_status = AccountStatus.ACTIVE
class AccountStatus(Enum):
ACTIVE = "ACTIVE"
BLOCKED = "BLOCKED"
CLOSED = "CLOSED"
class Search(object):
def __init__(self):
pass
def search_room(self, room_style: RoomStyle, start_date: Optional[str], duration: int) -> List[Room]:
pass
class Booking(metaclass=ABCMeta):
@abstractmethod
def create_booking(self, guest_info: Guest) -> RoomBooking:
pass
@abstractmethod
def cancel_booking(self, booking_id: int) -> RoomBooking:
pass
# decorator pattern to calcute the cost
class BaseRoomCharge(metaclass=ABCMeta):
@abstractmethod
def get_cost(self) -> float:
pass
class RoomCharge(BaseRoomCharge):
def __init__(self, cost: float):
self._cost = cost
def get_cost(self) -> float:
return self._cost
class RoomServiceCharge(BaseRoomCharge):
def __init__(self, cost: float):
self._cost = cost
def get_cost(self) -> float:
room_charge = RoomCharge(55.55)
return room_charge.get_cost() + self._cost
class InRoomPurchaseCharge(BaseRoomCharge):
def __init__(self, cost: float):
self._cost = cost
def get_cost(self) -> float:
room_charge = RoomCharge(55.55)
return room_charge.get_cost() + self._cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment