All lessons in Software Engineering: Programs, Systems, and Maintainable Software
Requirements, Use Cases, and Acceptance Examples
Turn ambiguous lending rules into actor goals, alternate flows, and observable acceptance examples.
35 minutes · Free lesson
What you will learn
- Convert an ambiguous request into an actor goal and observable behavior.
- Specify alternate flows and failure postconditions for a command.
- Choose acceptance examples that distinguish competing interpretations.
“The library should let members borrow books” sounds clear until implementation begins. Does book mean a title or a physical copy? Can a suspended member borrow? Does returning an item delete its loan? What happens when two desks act at once? Requirements work exposes these questions before each developer answers them differently in code.
Your task is to specify a small, useful lending operation. The outcome is a compact set of rules and examples a reviewer can use to evaluate an implementation. It is not a collection of vague wishes or a complete description of every future library feature.
Separate the actor's goal from interface steps
An actor is a role interacting with the system. A staff member may record a borrowing on behalf of a member; an administrator may retire a copy. The actor's goal is the result they need, not the sequence of buttons they happen to press today.
“Record a loan for an eligible member and a lendable copy” remains meaningful if the interface changes from a form to a command-line tool. “Click the blue button” describes one implementation. Keep the goal independent of presentation so requirements can guide more than one interface.
Choose a consistent level of detail. “Run the library” is too broad for one use case. “Validate one character of a member ID” is an implementation step. Borrowing a copy is a useful transaction-sized goal with a clear beginning and outcome.
Name preconditions, guarantees, and extensions
A use case needs an initial context and observable end states. Preconditions describe assumptions that must already hold to start the operation. Inputs requiring validation are often better described as alternate flows than as assumptions the implementation can ignore.
For borrowing, assume the operator is using an authorized local application. Treat unknown member IDs, invalid dates, and unavailable copies as explicit input or state failures. The successful guarantee is a persisted active loan. The minimal guarantee on failure is that existing loan history and availability have not been partially changed.
An alternate flow says where the main flow diverges, what result the actor sees, and what remains true. “Handle errors” is not enough. For an already borrowed copy, the service rejects the borrowing, does not create a second active loan, and leaves the original loan intact.
| Part | Borrowing specification |
|---|---|
| Actor and goal | Staff records a loan on behalf of a member |
| Inputs | Stable member and copy IDs; borrowed and due dates |
| Success | Exactly one new active loan records the accepted inputs |
| Unknown reference | Reject; retain all existing records |
| Invalid date interval | Reject if due date precedes borrowed date |
| Conflict | Reject if another active loan already exists for the copy |
| History rule | Returning later preserves the loan rather than deleting it |
Do not require a particular table name or class layout unless the external contract truly depends on it. Requirements describe behavior; the design decides how to realize it.
Use examples to resolve ambiguity
An acceptance example contains a concrete starting state, action, and expected result. It is useful when different reasonable implementations would behave differently. A single ordinary success case often fails to settle the important questions.
Dates make boundary ambiguity visible. If borrowing on October 1 with a due date of October 1 is valid, the rule is due date greater than or equal to borrowed date. If it is invalid, the comparison is strictly greater. Record the chosen rule instead of leaving the operator to discover it through a rejection.
Examples should include non-events. When a borrowing fails, assert that no new loan was persisted and no existing return date changed. A result message can be correct while the stored state is wrong. Negative guarantees make partial updates visible.
Worked example
Turn a short request into distinguishing examples
- Request: a member can borrow an available book for up to fourteen days.
- Resolve identity: availability applies to a physical copy. Two copies of the same title may be borrowed independently.
- Resolve the interval rule with the stakeholder: the due date may equal the borrowed date and must be no later than fourteen calendar days after it.
- Example A: copy C1 is available; borrowed October 1 and due October 15 succeeds because the difference is fourteen days.
- Example B: the same dates with due October 16 fail and create no loan.
- Example C: C1 is active but C2 represents the same title and is available. Borrowing C2 succeeds; borrowing C1 fails.
- Record that the fourteen-day rule is an additional product decision. The base course model only requires a nonnegative date interval until this rule is explicitly implemented.
The final step matters. A worked extension should not silently change the shared case's baseline. Requirements are versioned decisions, and examples must state which version they test.
Check nonfunctional requirements with a workload
A quality requirement needs a context. “The report must be fast” cannot be reproduced. “On the stated local fixture containing 10,000 copies and 100,000 loans, the active-loan report returns the correct rows within the agreed measurement budget” names a workload and a result.
Choose a measurement method before claiming compliance. Repeated timings, warm versus cold caches, concurrent activity, and output size can change the result. For this course, record those factors and compare alternatives on the same fixture. Do not convert a single local result into a general capacity promise.
Maintainability can also be evaluated through tasks. Ask whether a loan policy can be changed in one domain module without editing unrelated SQL reports. This is more concrete than claiming that code is clean because it uses a named architecture.
Maintain traceability without a bureaucracy
Give each important rule an identifier and map it to at least one example, implementation boundary, and test. A small table is sufficient. When a requirement changes, update the rule and the distinguishing examples before modifying code.
Review contradictions explicitly. If one document says history is retained and another says returned loans are deleted, no implementation can satisfy both. Treat clarification as part of engineering work. Where a decision remains open, mark it as open and avoid presenting an assumption as an agreed requirement.
Exercise
A requirement says overdue members cannot borrow. List four missing definitions that could produce different implementations.
Check your answer
Define overdue at which observation date and timezone; whether any active overdue loan blocks all borrowing or only borrowing of another copy; whether a loan due today is overdue; and whether returning the overdue loan immediately restores eligibility. Other valid questions include grace periods and an operator override. Each answer needs an acceptance example.
Exercise
Write an alternate flow for attempting to return an unknown loan. Include the stored-state guarantee.
Check your answer
The service looks up the stable loan identifier, finds no matching loan, and reports an unknown-loan error. It creates no loan or return record and changes no copy or member state. A test snapshots relevant rows before and after the rejected command and verifies equality.
Exercise
Two stakeholders disagree about whether a member may borrow two copies of the same title. What artifact would help resolve the disagreement without selecting a database design prematurely?
Check your answer
Use a concrete acceptance example with member M1, title T1, copies C1 and C2, and an existing active loan of C1. Ask whether borrowing C2 should succeed. Record the agreed result and its rationale as a rule. Only then choose how to enforce that rule in the domain and database.
Summary
A useful requirement names an actor goal, observable guarantees, and meaningful failure behavior. Concrete examples settle boundaries and expose contradictions. Keep implementation choices separate until the behavior is clear, and trace changed rules into their tests.
Next action
Write five acceptance examples for borrowing and returning: an ordinary success, a date boundary, an unknown reference, an unavailable copy, and a repeated return. Include unchanged-state assertions.