1.2 What's So Hard about Telling Good Stories?
Writing use cases was supposed to be easy. One reason for their popularity is that a well-written use case is relatively easy to read. People may suppose that easy-to-read also means easy-to-write, but that is a mistake. It can be terribly hard to write easy-to-read stories. Use cases are stories, prose essays, and so bring along all the associated difficulties of story writing in general. As Rusty Walters remarked in Writing Effective Use Cases (Cockburn 2001, p. 205), "I did not understand this as the fundamental problem for [the first] four years."
The following example illustrates some very common mistakes encountered by teachers of use case writing. This use case fragment describes the actions a student performs when registering for her courses. It is not a horrible use casewe have all written some like thisbut it is a long way from being a good use case.
Use Case 1.1 Use Case Horror: Example of a Poorly Written Use Case
Register for Course (Main Scenario, Poorly Written Version)
Display a blank schedule.
Display a list of all classes in the following way: The left window lists all the courses in the system in alphabetical order. The lower window displays the times the highlighted course is available. The third window shows all the courses currently in the schedule.
Do
Student clicks on a course.
Update the lower window to show the times the course is available.
Student clicks on a course time and then clicks on the "Add Course" button.
Check if the Student has the necessary prerequisites and that the course offering is open.
If the course is open and the Student has the necessary prerequisites, add the Student to the course. Display the updated schedule showing the new course. If no, put up a message, "You are missing the prerequisites. Choose another course."
Mark the course offering as "enrolled" in the schedule.
End do when the Student clicks on "Save Schedule."
Save the schedule and return to the main selection screen.
The problems with this fragment include:
Too much user interface detail. In many poorly written use cases, we often see references to mouse clicks, list boxes, and window design. In the normal course of events, the use case is written as a set of requirements that the system must satisfy. The user interface design details are not usually requirements; they are usually design choices. Those design choices are made later, after the use cases have been written and reviewed. The initial design choices are often changed during development, still satisfying the overall requirements. Use case experts u universally warn against including the user interface design inside use cases. Doing so is costly because it adds writing and reviewing time, and it makes the requirements document longerand more likely not to be read carefully. Furthermore, it makes the requirements set "brittle," in the sense that small design decisions will invalidate or force an expensive revision of the requirements document. This is the single most critical mistake to avoid. The Adornments (p. 133) and TechnologyNeutral (p. 167) patterns describe how to steer clear of excessive detail.
Too many use cases at low goal levels. Computer programmers, who often are "stuck" with the job of writing the requirements document, have a tendency to produce numerous low-level use cases on the level of "Authorize user". These writers are very interested in describing individual system functions and features, largely because those are the functions they will have to implement. However, requirements documents written at such a level are very long, and difficult for end users to read. These documents do not show well what the system will contribute to the lives of the end consumers of the system. The CompleteSingleGoal (p. 118) pattern describes how properly to structure use cases to avoid this problem.
Using a use case for non-behavioral information. Sometimes writers are told, "Use cases are great. Write everything in use cases." But a use case is not good for everything; it is really only good for describing behavior. Everything that the system must do should really go into a use case, but everything else should really go into some other format. Some writers will produce immensely detailed use cases describing the completion of a user interface form, with each field in the form getting one or two lines of description. A much better approach is to create an Adornment by simply attaching the form to the back of the use case and writing in the appropriate step: "User provides the information on form XYZ (see attachment)." This shortens both the writing and the reading, without sacrificing detail. Performance requirements, complex business rules, data structures, and product line descriptions are all valuable, but better captured with other requirements tools such as tables, formulas, or state machinesor placed in another section of the requirements document.
Too long. The above three common errors produce use cases that are long and hard to read. A well-written use case is short, usually only three to nine steps long. (Oddly, many people feel embarrassed with such a short start to their use case. They should not fear, however, as there are usually more than enough extension conditions to make the use case worth writing and reading.) The pattern LeveledSteps (p. 153) describes how to write balanced, reasonably sized use cases.
Not a complete goal accomplishment. While shorter is better, some use case writers do not capture the complete behavior for goal accomplishment, but only u describe a fragment of the necessary behavior. This causes trouble during implementation, since the use cases do not connect to each other, and the programmers have to guess how to sew them together. A related mistake is not considering all the possible failure conditions or alternative behaviors. Once again, the programmers will discover these in their programming, and will either have to guess at what to program or bring the project to a halt while someone investigates what the system should do. The patterns CompleteSingleGoal (p. 118) and ExhaustiveAlternatives (p. 129) provide advice on associating goals with use cases and including all necessary failure conditions.
Sentence fragments. A relatively minor, but still noticeable, mistake is writing in sentence fragments, as done in the poorly written example of Use Case 1a. One could argue that such minor writing errors don't matter, but on all but the smallest projects there are many use case writers and readers. Omitting the actors' names in the action steps easily causes confusion over the course of the project, a damage far greater than the cost of simply remembering to write full sentences at the beginning. The pattern ActorIntentAccomplished (p. 158) describes how to write scenarios with clear, unambiguous steps.