Loading...
Room names will be {floor-row-col}
For each class, define the attributes (data) it will hold and the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.
class RoomStatus(Enum):
AVAILABLE = 1
BOOKED = 2
MAINTENANCE = 3
class SeasonMultiplier(Enum):
SUMMER = 1.75
SPRING = 1.5
FALL = 1.5
WINTER = 1
class PricingStrategy:
def getPrice(self, season, price):
pass
class smallRoomPrice(PricingStrategy):
def init(self):
super().init()
def getPrice(self, season, price):
return price * season * 1
class mediumRoomPrice(PricingStrategy):
def init(self):
super().init()
def getPrice(self, season, price):
return price * season * 1.25
class largeRoomPrice(PricingStrategy):
def init(self):
super().init()
def getPrice(self, season, price):
return price * season * 1.5
class Room:
def init(self, roomSize, roomName, price):
self.roomSize = roomSize
self.roomName = roomName
self.status = RoomStatus.AVAILABLE
self.price = price
def updateRoomStatus(self, roomStatus):
self.status = roomStatus
class Floor:
def init(self, floorPlan, hotel, floorNumber):
self.availableRooms = defaultdict(int)
self.floorRooms = []
self.floorNumber = floorNumber
for row in range(len(self.floorPlan)):
newFloorRooms = []
for col in range(len(self.floorPlan[0])):
roomSize = self.floorPlan[row][col][0]
roomPrice = self.floorPlan[row][col][1]
self.availableRooms[roomSize] += 1
hotel.availability[roomSize] += 1
newFloorRooms.append(Room(roomSize, f"{self.floorNumber}-{row}-{col}", roomPrice))
self.floorRooms.append(newFloorRooms)
class Hotel:
def init(self, hotelName, listOfFloorPlans):
self.hotelName = hotelName
self.listOfFloorPlans = listOfFloorPlans
self.availability = defaultdict(int)
self.hotelFloors = [
floor(self.listOfFloorPlans[floorNumber],self,floorNumber)
for floorNumber in range(len(listOfFloorPlans))
]
def checkIn(self, floor, row, col, season):
self.checkPrice(floor, row, col, season)
# logic to handle payment - probably third party API for payment
self.hotelFloors[floor][row][col].updateRoomStatus(RoomStatus.BOOKED)
def cancel(self, floor, row, col):
self.hotelFloors[floor][row][col].updateRoomStatus(RoomStatus.AVAILABLE)
# logic to return money - probably third party API for payment
def checkPrice(self, floor, row, col, season):
chosenRoom = self.hotelFloors[floor][row][col]
pricingStrategy = None
match chosenRoom.roomSize:
case RoomSize.SMALL:
pricingStrategy = smallRoomPrice()
case RoomSize.MEDIUM:
pricingStrategy = mediumRoomPrice()
case RoomSize.LARGE:
pricingStrategy = largeRoomPrice()
return pricingStrategy.getPrice(chosenRoom.price, season)
Race conditions can appear during changes to the state of the hotel rooms and floors
To avoid race conditions, i'd model each Hotel Floor and Hotel Room as a single threaded actor with individual event loops. By doing this, we can eliminate race conditions during operations on the internal states of the hotel floor and hotel rooms.