Design a library system Your results Progress Loading your progress
Results and the cheat sheet fill in as you go. Nothing here is locked; come back whenever you like.
Next path: Databases and SQL
Mastery by outcome Each outcome is backed by the checks that test it. Solid means every check was right first time; with hints means you got there with a nudge; worth a revisit means an answer was revealed or is still wrong.
1 Turn a paragraph of requirements into a list of classes, values and methods, and ask the questions that settle the rules before drawing.
Not yet 2 Keep a book apart from its copies, and put each rule (the loan limit, the due day, the fine) in the class that owns it.
Not yet 3 Build holds as a line of members, give a returned copy to the first one, and tell them through a method on the member.
Not yet 4 Run a low-level design round in its usual order and answer the common follow-ups by changing one place.
Not yet Your cheat sheet What each lesson leaves you able to do, in one place. Lessons you have not finished are dimmed, not hidden.
Ask about the rules before drawing: limits, loan length, fines, what happens when every copy is out, and what search matches. Say what is out of scope, such as paying fines or a hold that runs out, to keep the design small enough to finish. Sort the nouns of a requirement paragraph into classes (entities), values (fields) and names for things already on the list. Turn the verbs into methods on the class that owns the data each verb changes. Keep a title (Book: ISBN, title, author) apart from each thing on the shelf (BookCopy: its own id and status). Put the status on the copy, because two copies of one book can be in different states at once. Write a search that goes through the books, not the copies, and compares lower-case text. Use a Java enum for a fixed set of states where Python uses a string. Work a fine by hand: due day = day out + 14, days late = day back minus due day, fine = the larger of 0 and the days late, times 5. Check the loan limit first in borrow, and return at once when it is reached. Keep each rule in the class that owns its data: the limit with the member, the due day with the loan. Keep a rule that may change in its own class handed to the library (Strategy), so a new rule is a new class. Keep one queue of waiting members for each book, and take the first member off the front when a copy comes back. Hold a returned copy for that member, and let borrow accept a held copy only from the member it is held for. Tell the member through an update method every member has (Observer), so the library does not care how the message is sent. Read a sequence diagram of a return: the fine, the hold, the message, then the answer to the member who returned the book. Run a design round in order: questions and scope, nouns and verbs, the class diagram, the core code, then the follow-ups. Answer a new kind or a new rule by pointing at the one class that changes or the one class you add. Answer two users at once by naming the fix: finding and taking the last item must be one step nothing can interrupt. Practise with prompts such as an elevator, a vending machine, tic-tac-toe and movie tickets, timed at 45 minutes. Move a rule that depends on the kind of member into the member, so the library asks instead of checking. Write a second fine rule as a new class built on the first, with its own fine method. Predict a run with a new kind of member, and add a further kind without changing the library. Also builds on this