Bird
Raised Fist0

Which design approach best models this?

hard📝 Trade-off Q15 of Q15
LLD - Design — Hotel Booking System
You need to design a room type hierarchy for a hotel system that includes Room, Bedroom, ConferenceRoom, and Suite. Suites can have multiple bedrooms and a living area. Which design approach best models this?
AMake Suite inherit from Room and include a list of Bedroom objects plus living area
BMake Suite inherit from Bedroom and add living area attributes
CMake Suite a separate class unrelated to Room hierarchy
DMake Bedroom inherit from Suite to reuse features
Step-by-Step Solution
Solution:
  1. Step 1: Analyze relationships

    Suite is a special Room that contains multiple Bedrooms and a living area, so it should inherit from Room.
  2. Step 2: Model composition

    Suite should have a list of Bedroom objects (composition) to represent multiple bedrooms, plus its own living area attributes.
  3. Final Answer:

    Make Suite inherit from Room and include a list of Bedroom objects plus living area -> Option A
  4. Quick Check:

    Use inheritance + composition for complex types [OK]
Quick Trick: Use composition for multiple rooms inside Suite [OK]
Common Mistakes:
MISTAKES
  • Using inheritance to model 'has-many' relationships
  • Ignoring composition for complex room types
  • Making unrelated classes inherit incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes