Design: Room Type Hierarchy System
Design focuses on the class and object hierarchy for room types and their attributes. It excludes UI design, database persistence, and network communication.
Functional Requirements
Non-Functional Requirements
Jump into concepts and practice - no test required
RoomType (Base Class)
|
+-- Bedroom (Derived Class)
|
+-- MasterBedroom (Derived Class)
+-- GuestBedroom (Derived Class)
+-- Kitchen (Derived Class)
+-- Bathroom (Derived Class)Room type hierarchy in system design?Room with a subclass ConferenceRoom in a typical object-oriented design?extends is used to inherit from a base class.class ConferenceRoom extends Room {}. Others use incorrect or incomplete syntax.class Room:
def __init__(self, name):
self.name = name
class Bedroom(Room):
def __init__(self, name, bed_size):
super().__init__(name)
self.bed_size = bed_size
room = Bedroom('Master', 'King')
print(room.name, room.bed_size)Bedroom('Master', 'King') calls Bedroom's constructor, which calls Room's constructor with 'Master'.room.name is 'Master' from Room; room.bed_size is 'King' from Bedroom.class Room:
def __init__(self, name):
self.name = name
class MeetingRoom(Room):
def __init__(self, name, capacity):
self.capacity = capacity
room = MeetingRoom('Boardroom', 20)
print(room.name, room.capacity)super().__init__(name), so name is not set.room.name is missing, causing error or undefined behavior.Room, Bedroom, ConferenceRoom, and Suite. Suites can have multiple bedrooms and a living area. Which design approach best models this?