ooad1-7 Exercise 2: Nightly Overdue Notices ================================================ evening.fragments.mmd (Mermaid 12.1.0): sequenceDiagram participant Timer as Nightly Timer participant Desk as LoanDesk participant Notifier Timer->>Desk: send_overdue_notices(today) loop for each overdue loan Desk-)Notifier: email(member, loan) opt the member has a mobile number Desk-)Notifier: sms(member, loan) end end Desk-->>Timer: number of notices sent ex2.py (needs compare_diagrams.py and the class diagram source from the chapter folder): """Exercise 2: which operations does the new sequence diagram ask for that the class diagram does not have yet? Run from the chapter folder: py ex2/ex2.py""" import pathlib import re import sys HERE = pathlib.Path(__file__).resolve().parent.parent sys.path.insert(0, str(HERE)) from compare_diagrams import calls, class_operations # noqa: E402 source = pathlib.Path(__file__).parent / "evening.fragments.mmd" text = source.read_text(encoding="utf8") aliases = dict(re.findall(r"participant (\w+) as ([\w ]+)", text)) ops = class_operations(HERE / "diagrams" / "version_b.class.mmd") print("operations the diagram asks for (receiver.operation):") for sender, receiver, op in sorted(calls(source)): cls = aliases.get(receiver, receiver) status = "present" if op in ops.get(cls, set()) else ("class missing" if cls not in ops else "operation missing") print(f" {cls}.{op:<22} {status}") Run with: py ex2/ex2.py Output: operations the diagram asks for (receiver.operation): Notifier.email class missing Notifier.sms class missing LoanDesk.send_overdue_notices operation missing What the diagram says: the timer asks the desk to send notices; for each overdue loan the desk sends an email without waiting (an open arrow, a fire-and-forget message); an opt box holds the text message, sent only if the member has a mobile number. The final return reports how many notices were sent. Why loop around opt, not par: the email and text for one member are not required to happen at the same time; the question is whether the text happens at all, which is an opt. A par would be right if the two had to run concurrently and neither depended on the other. What the check found: three decisions are waiting. The class diagram has no Notifier; Notifier needs email and sms operations; and LoanDesk needs send_overdue_notices(today). Also visible in the diagram but not checked by the script: the desk must be able to list overdue loans, which is another operation (probably on the Catalogue), and a Member needs a way to say whether it has a mobile number. WHY THIS WORKS AS AN ANSWER --------------------------- Each arrow is an operation promise, so a sequence diagram doubles as a to-do list for the class diagram. The check is crude (it matches names, and it cannot see operations hidden inside a loop's condition), but it found the gaps in seconds.