LLD Modelling Quiz: Classes, Relations and Association Classes
Practise turning requirements into classes: ten questions on entities, association classes, where rules live and god classes, plus a course registry to code.
- Course: Low-Level Design study plan
- Module: From requirements to classes
- Kind: Checkpoint — cleared at 70%
- Reading time: 30 min
- Runtime: OpenJDK 18
Checkpoint — From requirements to classes is the checkpoint that closes the From requirements to classes module: a graded quiz and whole-program exercises, passed at 70%.
Instructions
This checkpoint covers the whole module: reading a brief for nouns and verbs, association classes, composition versus association, where a rule should live, and keeping the model free of I/O.
How it works. Ten questions and one program. You need 70% on the questions and the program accepted to clear the module; retake it as often as you like.
The program is a course registry with seats and a waitlist. Before you code, sketch it:
- Which classes hold state? Which one only finds objects and calls them?
- Which class decides between a seat and the waitlist, and who moves in when a seat frees up?
- Which collection keeps a student's courses in code order?
Hidden cases drop students from the waitlist as well as from seats, enrol someone twice and name students and courses that do not exist — the refusals are part of the design, so give each one a single home.
Common questions
How do you decide which nouns become classes?
A noun becomes a class when the system must remember something about it and it has behaviour of its own, such as a Book or a Course. Nouns that are only a number become fields or constants, and actors who merely call the system stay outside it.
When does a link between two objects need its own class?
When the link carries facts that belong to neither side alone. A course enrolment with its arrival order, a loan with its due day and a booking with its dates are association classes that both sides point at.
Exercise
Course registry with a waitlist
Model a course registry: Course (a code and a number of seats, the students enrolled and a waitlist, both in arrival order), Student, and a Registry that finds them. Commands, one per line until end of input:
| Command | Prints |
|---|---|
COURSE <code> <seats> | course <code>, capacity <seats> |
STUDENT <name> | student <name> |
ENROL <name> <code> | <name> enrolled in <code> when a seat is free, else <name> waitlisted for <code> at position <k> |
DROP <name> <code> | from the waitlist: <name> left the waitlist for <code>; from a seat: <name> dropped <code>, and when someone was waiting, <name> dropped <code>, <first waiting> moves in |
ROSTER <code> | <code>: <enrolled> | waitlist: <waiting>, each list space-separated in arrival order or none |
COURSES <name> | <name>: <codes enrolled, sorted> or <name>: none (waitlists do not count) |
Refusals print error: <reason>: course <code> already exists, student <name> already exists, no student <name> (checked first), no course <code>, <name> is already in <code> (enrolled or waiting), <name> is not in <code>, and unknown command <WORD>.