All lessons in Software Engineering: Programs, Systems, and Maintainable Software

UML Model Review

Use class, sequence, and state diagrams to investigate one design question.

30 minutes · Free lesson

What you will learn

  • Select a class, sequence, or state diagram for a specific design question.
  • Interpret identity, multiplicity, and message order without treating diagrams as implementation proof.
  • Find a contradiction between two views of the same lending behavior.

A diagram is useful when it makes an unanswered question easier to examine. A class diagram can reveal that one title has many physical copies; a sequence diagram can expose a write occurring before validation; a state diagram can reveal a missing return transition. Drawing all three without a question can create documentation that no one maintains.

This optional review uses the lending model to practice choosing and checking a representation. The deliverable is a small set of consistent views, not mastery of every modeling symbol.

Use a class view for structure

Show Title, Copy, Member, and Loan with their relevant identifiers and relationships. A copy belongs to one title; a title may have zero or more copies. A loan references one copy and one member; each of those may have many historical loans.

Multiplicity describes allowed relationship counts, but a static association alone may not express a conditional rule such as at most one active loan. Add that invariant as a constraint tied to the returned-date definition. Do not mark the entire copy-to-loan history as one-to-one merely to represent current availability.

Composition and aggregation notation can imply ownership semantics. Use them only when the lifecycle meaning is clear. If deleting a copy must not delete retained loan history, a diagram suggesting unconditional lifetime ownership would mislead implementers.

Use a sequence view for one scenario

A sequence diagram shows participating roles and messages over an interaction. For borrowing, include the input adapter, lending service, persistence boundary, and caller-visible result. Show the transaction boundary and the alternate conflict path.

The order of messages is meaningful. Validating a date after committing a loan contradicts the failure guarantee. Showing an availability query followed by an unconstrained insert may expose the concurrency gap, but a diagram of one caller does not itself prove safety under two callers.

Avoid drawing every internal helper call. Include the messages that explain decisions, ownership, and failure behavior. A diagram that requires updates for every private function rename may be too detailed for its purpose.

Worked example

Review two inconsistent views

  1. The class view permits many historical loans per copy and labels a loan active when returned_on is absent.
  2. The sequence view for return deletes the loan row after updating the screen.
  3. The sequence contradicts the history requirement even though the class view looks plausible.
  4. Replace deletion with a return-date update inside the persistence operation, then show the confirmed result reaching the interface.
  5. Add a return-failure alternative that leaves the original loan unchanged. The two diagrams now describe the same retained-history behavior.

A loan begins active and can transition to returned under a valid return command. Unknown loan identity is not a state of an existing loan; it is a lookup failure. An invalid date is a rejected event, not a successful state transition.

Separate orthogonal state when necessary. Copy retirement and loan activity may coexist: a retired copy can still have a loan that must be returned. Combining them into one simplistic available-borrowed-retired enum can accidentally remove a valid recovery path.

Label transitions with events, guards, and effects where those distinctions help. The guard for return includes a valid date and active loan; the effect records the return fact. A guard is not evidence that every implementation path enforces it, so connect it to tests and constraints.

Check diagrams against executable behavior

Choose one success trace and one rejected trace and walk them through every view. Confirm that entities and IDs have consistent names, multiplicities permit the observed history, and the sequence reaches only legal states.

Then compare the diagrams with the actual schema and tests. A diagram can document the intended contract, but implementation may diverge. Record whether each view is proposed, current, or historical so a reader knows how to use it.

Keep the source editable and close to the design note. A small text-based diagram can be easier to maintain than an exported image with no editable origin. The chosen tool matters less than whether changes to the relevant rule also update its view.

Exercise

A diagram gives each copy exactly one loan, while the requirement retains all returned loans and permits later borrowing. What change is needed?

Check your answer

Represent a copy as related to zero or more historical loans, then separately constrain the active subset to at most one. A fixed one-loan multiplicity incorrectly forbids valid history and conflates the current state with all past relationships.

Exercise

A state diagram includes a transition from returned back to active when the same copy is borrowed again. Why can this conflict with the course's loan identity model?

Check your answer

The model creates a new loan identity for a new borrowing and retains the old returned loan unchanged. Reactivating the original loan would overwrite or confuse its historical dates and borrower. The copy becomes available again, but the old loan remains returned.

Summary

Choose a diagram for a specific structural, interaction, or transition question. Keep identity, multiplicity, and history consistent across views. Diagrams guide review but must be checked against constraints, implementation, and executable evidence.

Next action

Create one class view and one return sequence for the lending system. Walk a borrow-return-borrow history through both and identify the constraint that cannot be expressed by multiplicity alone.

Choose another lesson