ooad1-1 Exercise 3: From Sketch to Code, and What the Sketch Missed ====================================================================== ex3.py (run with Python 3.14): from dataclasses import dataclass, field from datetime import date @dataclass class Book: title: str @dataclass class Reservation: book: Book reserved_on: date @dataclass class Member: name: str reservations: list[Reservation] = field(default_factory=list) def reserve(self, book: Book, today: date) -> Reservation: r = Reservation(book, today) self.reservations.append(r) return r ada = Member("Ada") ada.reserve(Book("Dune"), date(2026, 10, 10)) ada.reserve(Book("Dune"), date(2026, 10, 11)) # the diagram does not forbid this print(len(ada.reservations), "reservations, both for", ada.reservations[0].book.title) Output: 2 reservations, both for Dune What the diagram does not say, and the code therefore allows: 1. The same member reserving the same book twice (the output shows it happening). Is that allowed? 2. How long a reservation lasts, and what happens when it expires. 3. What happens when the book is available now: is a reservation still needed? 4. Whether there is a limit on reservations per member. 5. The order of the queue when several members reserve one book: first come first served, or something else? 6. Whether a member can cancel, and who may cancel for them. Questions for the librarian: the six above, in plain words. Questions 1, 4 and 5 are business rules; 2, 3 and 6 also decide the states a reservation can be in, which is chapter 8. WHY THIS WORKS AS AN ANSWER --------------------------- The code was run, and the second reserve() call succeeding is a concrete demonstration that the diagram's multiplicity "0..*" allows duplicates. A sketch states structure, not rules; turning it into code makes the missing rules show up as places where you had to choose, or where nothing stops a bad case.