Domain Model
Object-Oriented Design with UML
Course 1 ยท Chapter 4 ยท The Domain Model
Chapter 3 described what people want to do. This chapter describes the world those wishes live in: the things the library cares about, and how they relate. That picture is the domain model: a class diagram, but of real-world concepts (a member, a loan, a fine), not of software classes. It is the vocabulary the team will share, and it is the cheapest place to find a misunderstanding, because you can show it to a librarian.
Conceptual Model, Design Model
The same notation, drawn for two readers, answers two different questions:
| Domain (conceptual) model | Design model | |
|---|---|---|
| Describes | Things in the problem world | Classes in the software |
| Contains | Concepts, attributes, associations, multiplicity | Also operations, visibility, types, interfaces, helper classes |
| A "Member" class has... | name, card number, expiry date | Those, plus methods like borrow() and perhaps a database id |
Has a LoanService, a Database, a Controller? | No: a librarian has never heard of them | Yes, probably |
| Can be reviewed by | A librarian | A developer |
| Chapters | This one | 5 to 7 |
The domain model is also not a database schema. It will often map onto one, but its job is understanding, so it ignores keys, indexes, join tables and anything the librarian would not recognise.
Finding the Concepts
Three sources, in order of reliability: the people who know the domain (ask what they call things, and what they confuse), the documents you already have (the use cases), and the existing paper and forms (a library's membership card and fine slip name real concepts). The classic technique is noun and verb analysis: underline the nouns in the requirements as candidate concepts and attributes, and the verbs as candidate relationships.
I ran a crude version over the two use case descriptions from chapter 3 (Borrow a Book and Return a Book): a script that counts the words, ignoring a hand-made list of common words and obvious verbs. There is no language-analysis library on this machine, so this is just counting; the point is the shape of the result:
The top of the list is encouraging: member, librarian, book, loan, copy, fine, card, membership. But it is a list of candidates, and the work is deciding what each word is:
| Word | Decision | Reason |
|---|---|---|
| member | Concept | Has its own facts and relationships |
| librarian | Not in the model | An actor: a role of someone using the system (chapter 3). If the library also needs to know which librarian did what, a Staff concept may come back later |
| book and copy | Two concepts: Title and Copy | The text uses "book" for both an ISBN-identified work and a physical item (see below) |
| loan | Concept | A transaction with its own dates; it comes from the verb "borrows" |
| fine | Concept | It has its own amount, date and "paid" status, and arises from a particular loan |
| due, date, days | Attributes | "Due date" is a fact about a loan |
| card, isbn | Attributes | Identifiers of a Member and of a Title (cardNumber, isbn) |
| membership, valid | Attribute (expiresOn) | Whether it is valid is worked out from a date; it is not a thing |
| held, hold, shelf | A status of a Copy | The hold is a state, not a separate thing. The words are the librarian's, which is why they are in the glossary |
| available, open, unpaid | Statuses | Values of an attribute |
| limit, lending | Rules, not concepts | "At most 5 loans" is a business rule; it goes in the use case or a constraint |
| library, desk, box, sea | Not in the model | The library is the scope; the rest is noise (the word "box" came from "black box", "sea" from "sea level") |
| reservation | Concept | It appears only once in the text, so counting would have missed it; I knew it from the stakeholders and from chapter 3's other use cases |
Where Noun Analysis Fails
- It finds words, not meanings. "Book" and "copy" are different concepts hiding behind overlapping words (a later section shows what it cost).
- It misses what the text rarely says. "Reservation" appears once. Counting would drop it; a stakeholder would not.
- It cannot tell a concept from an attribute from a status. Every row of the table above needed a human decision. A useful test: if it only has a value (a number, a date, a piece of text), it is an attribute; if it has its own facts or relationships, it is a concept.
- Plurals and synonyms split the count. "fine" (6) and "fines" (4), "loan" and "loans", "book" and "book's" are counted apart. A real analysis also has to merge "reservation" and "hold" or decide that they differ.
- Actors and interface words look like concepts. "Librarian" scored second; it does not belong.
- Verbs hide concepts. "A member borrows a copy" is where Loan came from: the relationship has facts of its own (when, until when, returned or not), so it became a thing. Look at verbs for this.
Larman's alternative (from memory) is a category list: prompt yourself with kinds of thing (physical objects, transactions, roles, places, records, events, catalogues) and ask whether the domain has one of each. Used beside noun analysis it finds what counting misses. Neither replaces asking.
Attributes, Associations and Multiplicity
- Attributes are the facts a concept holds: a Member has a
name,cardNumber,joinedOn,expiresOn. In a domain model keep them to what is meaningful in the domain and leave out types and ids. - Associations are meaningful relationships between concepts: "a Member borrows a Loan"; "a Loan is of a Copy". Name each one with a short verb phrase, so the diagram reads as sentences.
- Multiplicity says how many of one end may relate to one of the other:
1exactly one,0..1optional,0..*any number,1..*at least one. Read it as the number of things at that end for each one at the other end.
The Library's Domain Model
Rather than draw the diagram by hand and then write the sentences by hand (and let them drift), I wrote the model once, as data, and a small script produces both. Associations are written as "each LEFT has this many RIGHT".
Mermaid, generated by model.py. Lines are plain associations: at the domain level, who can navigate to whom is a design decision, not yet made. The diagram is wide; the text is easier to read in the sentences below.
Reviewing It With a Non-Programmer
A librarian will not read UML, and does not need to. Read the model aloud as sentences; the script's output, verbatim:
Every sentence is a claim the librarian can accept or reject, and a few of these are not obviously right, which is the point. "Each Fine arose from exactly one Loan": what about a fine for a lost book, or for a late payment of something else? "Each Reservation is for exactly one Title": could a member ask for a specific edition? "Each Member owes zero or more Fines": is a fine ever paid in part? I recorded these as open questions rather than answering them myself. Showing sentences instead of boxes also hides nothing: a librarian reading "each Title has as a copy zero or more Copies" notices that a title with no copies is allowed, and can say whether a title nobody owns any more should stay on record.
A Glossary
A domain model is only useful if the whole team uses its words the same way, so write them down. One line per term, in the domain's own language, plus the words you decided not to use:
The glossary entry for Copy says "never just 'book'", and that rule came from a real mistake, below.
What the Model Found in Chapter 3
In chapter 3 the Borrow use case, and the Python written from it, identified the item being lent by ISBN. The domain model says an ISBN identifies a Title, and the library may own several Copies of one title. Here is chapter 3's code with two physical copies of ISBN 111 on the shelf and two members:
The code's dictionary of copies is keyed by ISBN, so the two copies collapse into one, and the second member is told the book is on loan when a copy is sitting on the shelf. This is not a coding slip; it is a vocabulary error in the requirement, which the model's two separate boxes make obvious. Chapter 3's page now records it. The fix belongs in the use case ("the copy's barcode") and in the model, not in the dictionary.
What Multiplicity Cannot Say
The diagram says a Copy can have 0..* Loans. That is true over time. What it cannot say is the rule that matters: at most one of them may be open at once. That is a constraint, and it belongs beside the diagram as a sentence (UML has a formal constraint language, OCL, which I do not teach here). Here is the model as a first plain Python design, with the rule enforced, and a run that shows both halves:
Two members borrow Dune at once with two copies of one title, which the old ISBN-keyed code could not do. The same copy cannot go out twice, and can go out again after it returns, leaving two loans in its history with one open. A domain model plus its constraints is more than the picture; keep a short list of such rules next to it.
- My own earlier chapter had the wrong vocabulary. Chapter 3 treated an ISBN as the identity of a physical book. What went wrong: I used the word "book" for two concepts and never asked which. How to avoid it: before writing flows, write the glossary; and when a single noun is used in two senses ("we have the book"/"the book is on loan"), split it.
- "Copys". My generated sentences read "each Title has as a copy zero or more Copys", because my pluraliser just added an "s". It is a small thing in a document the librarian is meant to read aloud, and an embarrassing one. I replaced it with a rule for words ending in "y". Takeaway: read generated text, and test hand-written pluralisation on the words your model really uses.
- A word count mistaken for analysis. My first instinct was to treat the top of the frequency list as the concept list. It contains an actor (librarian), two overlapping words (book, copy), statuses (held, available, open) and rules (limit), and misses "reservation". The table above is the real work. Takeaway: a tool that produces candidates is a prompt for judgment, not a replacement.
- Mermaid text does not say who reads it. The diagram has no arrowheads on purpose; at the domain level, navigation is undecided. Drawing arrows too early would have claimed a design decision (that a Copy cannot find its Loans) I had not made.
Hands-On Exercises
Here is a short description of a bike repair shop (in the solution file). Run a word count over it, then classify every candidate as concept, attribute, status, rule, actor or noise, and say what the counting missed or got wrong.
๐ View solutionWrite the bike shop's domain model as data (concepts with attributes, associations with multiplicities), generate the Mermaid diagram and the review sentences, render it, and name two sentences you would ask the shop owner about.
๐ View solutionThe bike shop has a rule its multiplicities cannot express: a bike can have only one job in progress at a time. Write it as a constraint in words, enforce it in Python, and write tests showing that many jobs over time are fine, two at once are refused, and finishing a job frees the bike. Run them.
๐ View solutionChapter 4 Quick Reference
- Domain model = class diagram of real-world concepts: attributes, associations, multiplicity; no operations, helper classes or database detail
- Sources: domain experts, use cases, existing forms; noun analysis for concepts and attributes, verbs for relationships (and for hidden concepts like Loan); a category list as a second prompt
- Concept vs attribute: if it only has a value, it is an attribute; if it has its own facts or relationships, it is a concept
- Noun analysis is a source of candidates: it misses rarely mentioned things, confuses actors, statuses and rules with concepts, and cannot see that one word means two things
- Multiplicity:
1,0..1,0..*,1..*; read as "for each one at the other end, how many at this end" - Multiplicity cannot express "at most one open at a time": write such rules as constraints beside the diagram and enforce them in code
- Review with non-programmers by reading associations as sentences; keep a glossary, including the words not to use
- A domain model usually corrects the use cases written before it; expect to go back