CSE Roadmap

Core tier · about 2 hours · 7 parts

Part 5 of 7 · 1 min read

First class list

Write the classes, then trim.

From section 3, a first list for the room system:

  • Room (id, capacity, floor)
  • User (id, name)
  • TimeSlot (start, end), with overlaps
  • BookingStatus (enum: CONFIRMED, CANCELLED)
  • Booking (id, room, user, slot, status), with cancel
  • BookingService (list of bookings), with book, cancel, findFreeRooms

Seven names for a small prompt is fine. Then trim: does each class have a requirement behind it? User is only an id here, so a String userId inside Booking could replace the class. Either choice can be defended. The rule is to say which choice was made and why.

enum BookingStatus { CONFIRMED, CANCELLED }

record Room(String id, int capacity) {}

Common trap: adding a class "because a real system has it". A Building class with no requirement behind it is cost without benefit.

Common mistake

Turning every noun into a class. Capacity and floor are attributes. A status with two values is an enum.

Check yourself: 1. Which class in the list could be dropped, and what replaces it? 2. Why is BookingStatus an enum and not a class? 3. What does "a class needs a requirement behind it" mean?