Writing effective Use Case Examples
|
A great way for writing effective use cases is to walk through a simple use case example and watch how it can
be leveraged to something complex. By absorbing the meaning of what use case diagrams, alternate flows and basic flows, you will be able to apply use cases to your projects.
In this section, I'm going to walk you through writing effective use cases for a mock Ebay site. Most of
us know and love Ebay, so if you don't know Ebay, go to Ebay and navigate through the site and come
back to our example. Imagine that only you know Ebay, but nobody has ever seen Ebay and you have to write the requirements
for Ebay using use cases, and explain it to people who have never seen it.
|
|
|
|
|
When it comes to writing effective use cases, you
don't need to be a perfectionist and concern yourself with getting it right the first time. Developing
use cases should be looked at as an iterative process where you work and refine. You can always refine it later, so again, don't
go for perfection from the get-go. Loosen up and have some fun while you're doing it.
There are possibly over a dozen actors that interact with Ebay, from buyers and sellers, down to
suppliers, wholesalers, auditors, and customer service. But we're going for grass-roots, so who are the
basic users of Ebay? BUYERS and SELLERS. So lets put them down as our first actors. (The visual notation in
the figures below is based on UML -- Unified Markup Language for Use Cases)
Do you notice how the actors aren't John and Sue which would be people? While John may be a seller
and Sue may be a buyer, an actor is a Role. And a role in this case would be that of a buyer and
that of a seller. Now that things are clicking, lets throw some more actors on your paper just so we can try and
identify more possible users.
Now we have a bunch of actors. Wait a minute? Paypal? That's not a person. An actor can be a system, because a system plays another role in the context of your
new system and has goals and interacts with other actors as you will see later.
|
|
|
Now that you have established your actors (system users), or most of them, the next logical
step is to outline what the goals are of each actor. One you have established your actors and
the goals of each actor, you have now created your initial list of high level use cases. In the example below
you will see the representation of actor goals. Again, don't try and capture 100% of this step, in requirements management, refinement
is always part of the entire process. Effective use cases should have understandable actors and goals.
|
In this step, you are going to cross the bridge into object modeling. Don't get overly concerned
about terms like generalization, inheritance and extends. The goal of this Ebay use case example is to keep it
understandable so we will explain this concept in terms of the example.
What does the word general mean? Something is broad and not as detailed. Generalization is when
you "inherit" from something general and then add more detail. A "person" is very general. A "man" is still general, but not as general as a "person". You can say that a "man" inherits behavior
and atributes of a "person".
Look at the requirements management use case diagram above and you will see there is duplicate behavior in both the buyer and seller which includes "create an account" and "search listings". Rather than have all of this duplication, we will have a more general user that has this behavior and then the actors will "inherit" this
behavior from the new user.
The above use case example diagram illustrates that a generic user creates accounts and search listings and that a buyer and a seller have their own behavior but also have the behavior of the generic user. The benefits of generalization are that you eliminate duplicate behavior and attributes that will ultimately make the system more understandable and flexible. We will see in later steps that this inheritance applies both to use cases and to the actors.
After producing your initial visual list of use case actors and goals, we can take
this list and create an initial use case grid which provides the basis for the use case
index. Every use case will have various attributes relating both to the use case iteself
and to the project. At the project level, these attributes include scope, complexity, status
and priority.
This use case index should be used by the project team to define the use cases against. It will
serve as a master inventory to help writ effective use cases for the requirements phase of the project.
The actual use case is a textual representation illustrating a sequence of events. In our
use case example, you will see that there are several components of a use case which we
will review. In the mean time, review the table below to get a basic understanding of what is in the
use case and then we will review each element as we progeress through our use case example.
| Use Case Element | Description |
| Use Case Number | ID to represent your use case |
| Application | What system or application does this pertain to |
| Use Case Name | The name of your use case, keep it short and sweet |
| Use Case Description | Elaborate more on the name, in paragraph form. |
| Primary Actor | Who is the main actor that this use case represents |
| Precondition | What preconditions must be met before this use case can start |
| Trigger | What event triggers this use case |
| Basic Flow | The basic flow should be the events of the use case when everything
is perfect; there are no errors, no exceptions. This is the "happy day scenario". The exceptions
will be handled in the "Alternate Flows" section. |
| Alternate Flows | The most significant alternatives and exceptions |
Now that you have a general understanding of what a use case consists of, we are ready to start creating
our use case. Typically, while the name of your use case is being discussed, people will start briefly describing
the use case. Use plain english and keep it simple. Getting back to our use case example, I will begin with use case #1 from step number four.
| Use Case Number: | 1 |
| Use Case Name: | Buyer Places a Bid |
| Description: | An EBAY buyer has identified an item they wish to buy, so they will place a bid for an item
with the intent of winning the auction and paying for the item. |
STEP 8. Create the use case basic flow
The basic flow of a use case represents the most important course of events or what happens most of the time, sometimes referred to as the 'Happy
Day Scenario' because it is what occurs when everything goes well -- no errors or exceptions. Another reason why the basic flow is so critical
is because it's much easier to fully comprehend the exceptions once the norm is understood and if the basic flow represents 70% of
the system, the development staff is much more prone to implementing the correct code in the first pass.
For our use case example, the basic flow should be to describe the happy day scenario for your use cases such as "placing a bid". For a consumer
to play a successful bid, what is the primary flow when everything goes as planned. An effective use cases needs to have the basic flow before moving forward with writing the alternate flows.
The basic flow is the key ingredient to your use case and some can argue that you can stop once you're done with the
basic flow. It really depends on the level of detail you wish to achieve. However, providing more detail to the
consumers of your use case is always a good thing.
The alternate flows providing the following:
A few examples of alternate flows are:
While a customer places an order, their credit card failed
While a customer places an order, their user session times out
While a customer uses an ATM machine, the machine runs out of receipts and needs to warn the customer
Recently at a new project assignment, I introduced a mid level developer to the concept of use cases which was totally foreign
to him. Once walking him through the basic concepts and showing him the use case example, the lightbulb went off in his head
on how convenient and simple it was to grasp the project.
A few reasons why it's that much easier to learn a system through use cases then a traditional requirements document
is probably because with use cases, you are introduced to concepts at a high level, walk through a living scenario and then presented
with specifications last.
In several places in this document, I have stated "effective use cases" rather than just "use cases". The purpose of the use cases is for effective knowledge transfer from the domain expert to the software developer -- these use cases will serve as software requirements. If they don't make sense to the person building the software, they are not effective. There are several sources on the web for writing effective use cases including the book by Alistair Cockburn.
You can use the Gatherspace.com use case modeling tool to produce a use case model within a few clicks. Once you define your use cases and actors, just go into the reporting section and click on the 'Use Case Model' report and that's it. From the main use case model, you can continue to drill down into the use cases.
To see what this looks like, click the use case model sample now.
In several places in this document, I have stated "effective use cases" rather than just "use cases". The purpose of the use cases is for effective knowledge transfer from the domain expert to the software developer -- these use cases will serve as software requirements. If they don't make sense to the person building the software, they are not effective. There are several sources on the web for writing effective use cases including the book by Alistair Cockburn.
|