Loading...
The hotel booking system will serve as a platform for users to search for and book hotel rooms. Key features include:
Pending, Failed, Completed) and manage refunds for cancellations.The system's main objects include:
To promote code reuse and flexibility:
class User:
def __init__(self, user_id, name, email):
self.user_id = user_id
self.name = name
self.email = email
self.bookings = []
def search_rooms(self, location, check_in, check_out, room_type):
# Placeholder for searching logic
available_rooms = RoomManager.get_available_rooms(location, check_in, check_out, room_type)
return available_rooms
def make_booking(self, room, check_in, check_out):
if room.is_available(check_in, check_out):
booking = Booking(self, room, check_in, check_out)
self.bookings.append(booking)
room.mark_unavailable(check_in, check_out)
return booking
else:
raise Exception("Room is unavailable for the selected dates.")
def cancel_booking(self, booking_id):
booking = next((b for b in self.bookings if b.booking_id == booking_id), None)
if booking:
if booking.policy.allows_cancellation():
booking.cancel()
return f"Booking {booking_id} has been cancelled."
else:
raise Exception("Cancellation policy does not allow cancellation.")
class Room:
def __init__(self, room_id, room_type, price, availability_calendar):
self.room_id = room_id
self.room_type = room_type
self.price = price
self.availability_calendar = availability_calendar # Dictionary with dates and availability status
def is_available(self, check_in, check_out):
return all(self.availability_calendar.get(date, False) for date in range(check_in, check_out))
def mark_unavailable(self, check_in, check_out):
for date in range(check_in, check_out):
self.availability_calendar[date] = False
class Booking:
def __init__(self, user, room, check_in, check_out):
self.booking_id = generate_unique_id()
self.user = user
self.room = room
self.check_in = check_in
self.check_out = check_out
self.status = "Confirmed"
self.policy = CancellationPolicy()
self.payment = Payment(self)
def cancel(self):
self.status = "Cancelled"
self.payment.process_refund()
class Payment:
def __init__(self, booking):
self.payment_id = generate_unique_id()
self.amount = booking.room.price * (booking.check_out - booking.check_in)
self.status = "Pending"
def process_payment(self, method):
# Payment logic goes here
self.status = "Completed"
def process_refund(self):
# Refund logic
self.status = "Refunded"
class SeasonalPricing:
def __init__(self, season, multiplier):
self.season = season
self.multiplier = multiplier
def calculate_price(self, base_price):
return base_price * self.multiplier
class CancellationPolicy:
def allows_cancellation(self):
# Logic for checking refundability
return True
is_available and mark_unavailable methods prevent double booking.CancellationPolicy class handles refund and cancellation rules.RoomManager can implement thread-safe operations to handle concurrent booking requests.The design can handle growth by:
Here’s a simple class diagram for the system: