ooad1-4 Exercise 2: The Bike Shop Domain Model =============================================== ex2.py (uses model.py from the chapter, saved beside it): import pathlib from model import mermaid, sentences CLASSES = { "Customer": ["name", "phone"], "Bike": ["description"], "RepairJob": ["openedOn", "hoursWorked", "status"], "Mechanic": ["name"], "Part": ["partNo", "name", "pricePence"], "JobPart": ["quantity"], "Invoice": ["issuedOn", "totalPence"], } ASSOCIATIONS = [ ("Customer", "1", "owns", "0..*", "Bike"), ("Bike", "1", "is brought in for", "0..*", "RepairJob"), ("RepairJob", "0..*", "is done by", "1", "Mechanic"), ("RepairJob", "1", "lists", "0..*", "JobPart"), ("JobPart", "0..*", "is of", "1", "Part"), ("RepairJob", "1", "is billed by", "0..1", "Invoice"), ] REVERSE = {"owns": "is owned by", "is brought in for": "is the subject of", "is done by": "does", "lists": "is listed on", "is of": "is used in", "is billed by": "bills"} pathlib.Path("bike.domain.mmd").write_text(mermaid(CLASSES, ASSOCIATIONS), encoding="utf8") print("\n".join(sentences(ASSOCIATIONS, REVERSE.__getitem__))) Output (the review sentences): Each Customer owns zero or more Bikes. ...and each Bike is owned by exactly one Customer. Each Bike is brought in for zero or more RepairJobs. ...and each RepairJob is the subject of exactly one Bike. Each RepairJob is done by exactly one Mechanic. ...and each Mechanic does zero or more RepairJobs. Each RepairJob lists zero or more JobParts. ...and each JobPart is listed on exactly one RepairJob. Each JobPart is of exactly one Part. ...and each Part is used in zero or more JobParts. Each RepairJob is billed by at most one Invoice. ...and each Invoice bills exactly one RepairJob. Render (render_diagrams.py from chapter 2): rendered d\bike.domain.mmd -> bike.domain.mmd.svg (42 KB) What you should see: seven boxes in a chain: Customer, Bike, RepairJob, then Mechanic, JobPart and Invoice around RepairJob, and Part beyond JobPart. RepairJob is the hub. Two sentences to ask the owner about: 1. "Each RepairJob is done by exactly one Mechanic." What happens when two mechanics work on one bike, or one hands a job to another? If it happens, the multiplicity is wrong. 2. "Each RepairJob is billed by at most one Invoice." Can a customer be given a second invoice if a part is added after the first? And what about a job that is cancelled, so is never billed (which "at most one" allows)? Also worth asking: "Each Bike is owned by exactly one Customer." What happens when a bike is sold, or brought in by a friend? WHY THIS WORKS AS AN ANSWER --------------------------- The data drives both outputs, so the sentences always match the diagram. The questions come from sentences that sound plausible but constrain more than the owner may have intended: exactly-one multiplicities are the usual suspects.