Part 4 of 7 · 1 min read
Step 3
Decide who owns data and who owns each rule.
Step 3 turns names into responsibilities. For each class, write one sentence about its job. If a sentence needs the word "and" twice, split the class.
TimeSlot: holds a start and end, and says whether it overlaps another.Room: holds an id and a capacity.Booking: holds one reservation and its status, and can cancel itself.BookingService: keeps the list of bookings, checks the overlap rule before it accepts a new one, and cancels by id.
Then ask where each rule belongs. The overlap test between two slots belongs to TimeSlot, because it only needs the two slots. The rule "no overlapping bookings in one room" belongs to the service, because it needs to see many bookings.
Check yourself: 1. Which class says whether two slots overlap? 2. Why does the service own the room rule? 3. How can a class sentence tell you to split it?