0
0
LLDsystem_design~45 mins

Room type hierarchy in LLD - System Design Exercise

Choose your learning style9 modes available
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
FR1: Define different room types with common and specific attributes
FR2: Support inheritance of properties from parent room types to child room types
FR3: Allow adding new room types without changing existing code
FR4: Enable querying room types and their attributes
FR5: Support multiple levels of hierarchy (e.g., Room -> Bedroom -> Master Bedroom)
Non-Functional Requirements
NFR1: System should handle up to 1000 room types
NFR2: Query response time for room type details should be under 100ms
NFR3: System should be extensible and maintainable
NFR4: Memory usage should be optimized for embedded or low-resource environments
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
Base RoomType class or interface
Derived classes for specific room types
Attribute storage and inheritance mechanism
Factory or builder pattern for creating room types
Query interface for retrieving room type details
Design Patterns
Inheritance and polymorphism
Composite pattern for hierarchical structures
Factory pattern for object creation
Decorator pattern for adding attributes dynamically
Reference Architecture
RoomType (Base Class)
  |
  +-- Bedroom (Derived Class)
       |
       +-- MasterBedroom (Derived Class)
       +-- GuestBedroom (Derived Class)
  +-- Kitchen (Derived Class)
  +-- Bathroom (Derived Class)
Components
RoomType Base Class
Object-Oriented Programming (any language)
Defines common attributes and methods for all room types
Derived RoomType Classes
OOP inheritance
Specialize room types with specific attributes and behaviors
Attribute Storage
Class fields or dictionaries
Store attributes with inheritance support
RoomType Factory
Factory design pattern
Create room type instances dynamically
Query Interface
Methods or APIs
Retrieve room type details and attributes
Request Flow
1. Client requests details for a specific room type
2. Query interface calls the RoomType factory to get the instance
3. RoomType instance returns attributes, including inherited ones
4. Client receives complete room type information
Database Schema
Not applicable - design focuses on in-memory class hierarchy and inheritance
Scaling Discussion
Bottlenecks
Large number of room types causing memory overhead
Deep inheritance chains increasing lookup time for attributes
Difficulty in adding new room types without modifying base classes
Solutions
Use attribute dictionaries with caching to reduce repeated lookups
Limit inheritance depth and use composition for shared attributes
Implement a plugin or registration system for adding new room types dynamically
Interview Tips
Time: 10 minutes for requirements and clarifications, 20 minutes for design and explanation, 15 minutes for scaling and Q&A
Explain the importance of inheritance for code reuse and clarity
Discuss trade-offs between inheritance and composition
Show how design supports extensibility and maintainability
Mention performance considerations for attribute lookup
Highlight how the factory pattern helps in dynamic creation