Original URL: https://www.theregister.com/2007/11/23/use_case_part_two/

Model use cases that work

Think succinct

By Matt Stephens

Posted in Channel, 23rd November 2007 01:02 GMT

Book extract, part 2 In the first extract from their book Use Case Driven Object Modeling with UML: Theory and Practice, Reg Dev regular and Agile Iconoclast Matt Stephens and his colleague Doug Rosenberg introduced you to domain modeling.

In this, the second of four installments, the duo show you how to write useful use cases so the design, work estimates and tests flow logically out of each use case.

With an initial domain model in place, it's time to begin writing use cases – highlighted in red in the ICONIX Process map below.

Use case iconix process

Putting the use case model on the map

Use cases give you a structured way of capturing the behavioral requirements of a system, so that you can reasonably create a design from them. They help you to answer the fundamental questions of what are the users of the system trying to do and what is the user experience. A surprising amount of what your software does is dictated by the way in which users must interact with it.

Top 10 use case modeling guidelines

The principles discussed in this chapter can be summed up as a list of guidelines. These guidelines, in turn, can be summed up in a single sentence: describe system usage in the context of the object model.

In practical terms, this means you need to reference domain classes that participate in the use case, and you need to name your screens and other boundary objects explicitly in the use-case text. Otherwise, your behavior requirements will be completely disconnected from your object model, and - surprise - you won't be able to drive designs from the use cases.

Here, then, is this chapter's 10-point checklist for successful use case modeling. As with our list last time, pay attention because we shall be asking questions:

10. Reference boundary classes (like screens) by name

9. Reference domain classes by name

8. Write your use cases using a noun-verb-noun sentence structure

7. Write the use case in the context of the object model

6. Remember that your use case is really a runtime behavior specification

5. Use GUI prototypes and screen mock ups

4. Write your use case using an event/response flow, describing both sides of the user/system dialog

3. Write your use cases in active voice

2. Organize your use cases with actors and use case diagrams

1. Follow the two-paragraph rule, and don't pad out the use case with presentation details

Use case modeling in practice

Here's an exercise from the book, on opening an account. See how many errors you can spot in the following use case, and try to rewrite the use case text - hint: this relates back to the items numbered 10 and three in our list. Once you're done, compare your rewritten version with our "fixed" version. Good luck!

BASIC COURSE: The system displays the Create New Account page and enters the following fields: Username (must be unique), password, confirm password, first name, last name, address (first line), address (second line), city, state, country, zip/postal code, telephone number, and e-mail address. Then the user clicks the Submit button; the system checks that the Username is unique, creates the new user account, and displays the main Hub Page, along with a message indicating that the user account is now created and logged in.

ALTERNATE COURSES: Password and Confirm Password don't match: The page is redisplayed with a validation message.
Username not unique: The page is redisplayed and the user is asked to choose a different username.

What's wrong? Answer: This use case gets bogged down in presentation details. It spends too long listing the fields to be found on the Create New Account page, with the result that the text doesn't follow a noun-verb-noun sentence structure.

Padded-out use cases of this sort often take up much more than two paragraphs. This doesn't help, as you want your use case to be succinct enough to translate to a single sequence diagram. We'll come back to this point in the fourth and final part of this series.

Instead, the fields should be added as attributes to the appropriate class in your domain model - most likely the Customer class. Then, when you need them later, they'll be right there. The fixed version follows.

BASIC COURSE: The system displays the Create New Account page and enters the fields to define a new Customer account. Then the user clicks the Submit button; the system checks that the Username is unique, creates the new user account, and displays the main Hub Page, along with a message indicating that the user account is now created and logged in.

ALTERNATE COURSES: Password and Confirm Password don't match: The page is redisplayed with a validation message.
Username not unique: The page is redisplayed and the user is asked to choose a different username.

In this excerpt we covered how to write the kinds of use cases that can be used to drive a software design. In the next installment we tackle robustness analysis, a form of preliminary design that helps to prepare your use cases for detailed design, testing and coding.

Use Case Driven Object Modeling with UML: Theory and Practice is available for purchase through Register Books, at the special price of £34.99. ®