Smart Library Management
Actors and use cases, a SOLID-aware class diagram, and the Borrow Book interaction - the full front half of a design course.
beginner3-4 hours
What you will produce
- Actor and use-case list
- SOLID-aware class diagram
- Borrow Book interaction outline
The city library has funded a modernization project. Members should browse the catalog and borrow physical books, librarians manage inventory and member registrations, and the system itself sends due-date reminders and computes fines for late returns. You are the designer. Before anyone writes production code, the library board wants three things on the table: who uses the system and for what, a class model that will survive change requests, and a walkthrough of the most important interaction - borrowing a book.
This project takes you through the front half of a full design pass: actors and use cases, domain modeling, three SOLID principles applied where they actually earn their keep, and an interaction outlined message by message. You will produce three deliverables: an actor and use-case list, a SOLID-aware class diagram built in DiaGO Studio, and a numbered outline of the Borrow Book interaction.
None of this requires code, but the reasoning is exactly what you would do before writing any. The goal is not diagrams for their own sake - it is making design decisions cheap to change while they are still boxes and lines.
Before you start
You should be comfortable with:
- Objects and classes - what a class models and what belongs inside one
- Class diagrams - the notation you will use in Studio
- Associations - reading and writing multiplicities
New to the platform? Skim the introduction first. Then open the library-system starter example in DiaGO Studio - you will need it from Step 4 onward. Steps 1 and 2 are plain-text work; Step 3 uses the use-case editor and Step 9 is a written review, so keep a document open alongside Studio.
Step 1: Identify actors
In formal UML, an actor is a role outside the system boundary that interacts with the system. The word role matters: one person can play several actor roles, and one role can be played by many people. Separate primary actors - roles with goals the system exists to fulfill - from supporting actors, which the system calls on to get its work done.
Two actors here are obvious. The third is the one beginners miss: nothing in "send due-date reminders" is triggered by a human. By common convention, time itself - a scheduler or clock - is modeled as an actor, because something outside the system initiates that behavior. Some authors classify an initiating scheduler as primary since it kicks off a use case; others file it under supporting. Pick one convention and be consistent.
Complete this table on paper; two rows are done:
| Actor | Type | Goal or role |
|---|---|---|
| Member | Primary | Borrow and return books, pay fines |
| Time / Scheduler | Supporting (initiating) | Triggers due-date reminders on schedule |
| ... | ... | ... |
Step 2: Identify use cases
Name each use case after a goal a primary actor can achieve in one sitting, leaving the system in a consistent state: Borrow Book, Return Book, Register Member, Pay Fine. The test is whether an actor would say it: "I want to borrow a book" is a goal; "I want to update a book row" is not.
Complete the table; leave room for the reminder use case initiated by the scheduler:
| Use case | Primary actor | Goal |
|---|---|---|
| Borrow Book | Member | Take a physical book home with a recorded due date |
| Register Member | Librarian | Add a new member so they can borrow |
| ... | ... | ... |
Step 3: Draw the use-case diagram
Open the use-case editor in DiaGO Studio (or start from the worked Smart Library example to see one built out). Drop a system boundary for the library, place your actors outside it and your use cases inside, then connect each actor to the goals it initiates with an association.
Group use cases under the actor that initiates them - the shape you are aiming for:
Member
- Borrow Book
- Return Book
- Pay Fine
Librarian
- Register Member
- Manage Inventory
Time / Scheduler
- Send Due-Date ReminderNote any supporting-actor involvement, for example that Send Due-Date Reminder reaches the Member as a recipient. Where one use case always invokes another - Borrow Book must authenticate the member first - reach for an «include» relationship rather than a second association; the editor's tools on the left have it alongside «extend» and generalization.
Step 4: Identify domain classes
Open the library-system starter in Studio. Walk through each use case and pull out the nouns, then sort them: some are classes, some are attributes, some are noise. "Due date" sounds like a class until you notice it is a single value that belongs to a loan.
One classic library trap: the catalog entry ("Clean Code, 2008") and the physical item on the shelf (copy 3 of 5) are different things with different lifecycles. Model both - Book and BookCopy.
| Candidate | Source | Verdict |
|---|---|---|
| Book | Borrow Book, Manage Inventory | Keep - split into Book (catalog entry) and BookCopy (physical item) |
| Due date | Borrow Book, reminders | Attribute of Loan, not a class |
| Loan | Borrow Book, Return Book | Keep - links a Member to a BookCopy over a period |
| ... | ... | ... |
Step 5: Apply SRP
Who computes fines? Putting the calculation on Book gives a catalog entry a financial reason to change. Putting it on Member couples people to pricing. Loan knows the dates, and Information Expert rightly pulls the calculation toward it - but fine rules change on the library board's schedule, not the loan's. Grace periods, per-day rates, and caps are policy.
The Single Responsibility Principle is about reasons to change, so give the policy its own home: a FinePolicy class that takes a loan and today's date and returns an amount. When the board votes a new rate, exactly one class changes. Add it to your Studio diagram now.
Step 6: Apply OCP
Reminders go out by email today. SMS is on next year's roadmap, and push notifications after that. If a ReminderSender switches on a channel type internally, every new channel means editing - and re-testing - working code.
The Open-Closed Principle says to make that growth additive: define a NotificationChannel abstraction, and let each channel be its own class implementing it. Adding SMS becomes writing one new class, not touching the sender. In Studio, add the interface and one concrete channel with a realization relationship.
Step 7: Apply DIP
Step 6 created the abstraction; now point the dependency at it. LoanService - the class that orchestrates borrowing - must depend on NotificationChannel, never on EmailChannel directly. That is the Dependency Inversion Principle: high-level policy depends on an abstraction, and the volatile detail depends on the same abstraction from the other side.
interface NotificationChannel {
send(recipient: string, message: string): void;
}
class LoanService {
constructor(private readonly notifier: NotificationChannel) {}
}Reach for it
- The dependency points toward something volatile like IO or a vendor
- You can name at least two plausible implementations today
- You want to test the service without sending real messages
Avoid it
- The collaborator is a stable domain class such as Loan
- There is one implementation and no realistic pressure for a second
- The interface would forever mirror a single concrete class
Step 8: Complete the class diagram in Studio
Wire everything together with associations and multiplicities at both ends. A reasonable core: Member to Loan is 1 to 0..*, Loan to BookCopy is 0..* to 1, Book to BookCopy is 1 to 1..*, and FinePolicy is used by LoanService. Show EmailChannel realizing NotificationChannel, with LoanService associated only to the interface. When a multiplicity feels arbitrary, ask the domain: can a loan cover two copies? Can a copy exist without a catalog entry? Multiplicities are requirements written small.
Step 9: Draw the Borrow Book sequence
A class diagram shows structure; a sequence diagram shows the interaction over time. Open the Borrow Book sequence in DiaGO's sequence editor to see a worked version, then rebuild it from your own model. The interaction to capture:
1. Member -> LoanService: borrowBook(memberId, copyId)
2. LoanService -> BookCopy: isAvailable()
3. LoanService -> Loan: create(member, copy, dueDate = today + loanPeriod)
4. LoanService -> BookCopy: markBorrowed()
5. LoanService -> NotificationChannel: send(member contact, confirmation with due date)
6. LoanService -> Member: borrowing confirmedIn the editor, add each participant (Member as an actor, the rest as objects), then add the messages in order — a synchronous call for each request and a reply for the return. Stick to the happy path here; alternate flows come in Going further. Notice that step 5 works against the abstraction from Step 7 - the outline should not mention email.
Step 10: Explain your design decisions
Write one short paragraph for each of these, as if answering a design review: why FinePolicy exists instead of a method on Book or Member, why LoanService never names EmailChannel, and why Book and BookCopy are separate classes. If you cannot state the reason to change that motivates a decision, revisit the step that produced it.
Check your work
- Is every actor a role outside the system boundary - no actor named Database or LoanService?
- Is Time / Scheduler listed as the initiator of due-date reminders?
- Could an actor state each use case as a goal, with no CRUD-splinter entries?
- Does every association in your diagram carry multiplicities at both ends?
- Would adding an SMS channel require editing any existing class?
- When the fine rate changes, does exactly one class change?
- Does your Borrow Book outline mention only the abstraction, never a concrete channel?
- Does Studio's Issues tab show zero errors on your diagram?
Going further
- Reservations. A member reserves a book with no available copies and is notified when one returns. The Observer pattern is a natural fit - decide who observes whom.
- Persistence. Map your class diagram to a relational schema with ER modeling. The Book versus BookCopy split becomes a foreign key - notice what survives the translation and what does not.
- Alternate flows. Extend the Borrow Book outline with failure paths: no copy available, or unpaid fines above a threshold blocking the loan. Number them 2a, 2b under the step where they branch.
Practice
Run steps 1, 2, and 9 for a neighborhood tool-lending shed: residents borrow drills and ladders, a volunteer coordinator approves new residents, and the system nags borrowers after seven days. Produce the actor table, five goal-level use cases, and a numbered message list for Lend Tool. Time-box it to 40 minutes - speed reveals whether the method has stuck.