Design a Book fitness classes

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-05-19

Problem Statement

Design the low-level architecture of a system that allows users to book fitness classes at gyms or fitness studios. The system should manage class schedules, user bookings, cancellations, and availability.


🔷 Functional Requirements:

1.Add a Fitness Class:
•Admins/trainers can create a class with details like: name, trainer, location, start time, end time, capacity (max number of participants), and type (e.g., Yoga, Zumba, HIIT).
2.Search Available Classes:
•Users should be able to search for upcoming classes by type, location, date, or trainer.
3.Book a Class:
•A user can book a spot in a fitness class if it's not full.
•Booking should be prevented once the class is full.
4.Cancel Booking:
•A user can cancel their booking (within certain time constraints).
5.Waitlist Support (Optional):
•If a class is full, users can join a waitlist and will be auto-enrolled if a spot opens up.
6.Class Status:
•Allow status tracking for each class: SCHEDULED, FULL, CANCELLED, COMPLETED.


🔷 Constraints & Assumptions:

•Class times do not overlap for the same trainer or same room.
•Users can book only one instance of the same class.
•System can assume single location or extend to multi-location support.
•Don’t need to integrate payment or notification logic—just simulate.
•No real persistence needed—use in-memory storage (like maps/lists).


🔶 Expected Design Focus:

•Design classes like FitnessClass, User, Booking, ClassManager.
•Use enums for class status and class types.
•Ensure validation: capacity check, duplicate booking, timing clashes.
•Follow OOP and SOLID principles.
•Include interfaces if you're designing extensible modules (e.g., for BookingStrategy or SearchService).


🔷 Optional Bonus:

•Add trainer assignment constraints.
•Track user attendance history.
•Add a simple reward system for frequent attendees.


✅ Sample Flow:

1plaintext 2CopyEdit 31. Admin creates a Yoga class with max 10 participants. 42. 10 users book successfully. 53. The 11th user is rejected or added to waitlist. 64. One user cancels → 11th user is auto-booked (if waitlist is enabled).


Solution

Comments