In this example we're going to model out use case diagrams for a self-service machine.
The main functions of self-service machine is to allow a customer to by a product(s) from the machine (candy, chocolate, juice...). Every user that you asked for a set of scenarios happening during usage of machine, can tell you that main use case can be labeled as "Buy a product". Let's examine every possible scenario in this use case. These scenarios would be revealed trough conversations with users.
The "Buy a product" use case
The actor in this use case is customer. This customer wants to buy some of the products offered by the self-service machine. First of all he/she inserts money into the machine, selects one or more products, and machine presents a selected product(s) to the customer. Use case diagram for this scenario can be represented as:
The Buy a Product use case diagram |
But if we think a little, others scenarios immediatelly come to mind. It's possible that the self-service machine is out of one or more products, or the machine hasn't the exact amount of money to return to customer.
-Are we supposed to handle with these scenarios?
If we are, then let's return at the moment when the customer inserts money into machine
and enters his or hers selection. After this imagine that machine is out of brand. In this
case it's preferable to present a message to the customer that machine is out of brand and
allow him or her to make another selection or return money back. If
incorrect-ammount-of-money scenario has hapenned, then self-service machine is supposed to
return original ammount of money to the customer.
The precondition here is hungry or thirsty customer, and postcondition is either product
from the machine or the returned money.
This is use case scenario from one user's viewpoint (the customer). Buth there are other users too. A supplier has to restock the machine, and a collector has to collect the accumulated money from the machine. This tells us to create at least two more use cases: "Restock" and "Collect money". Let's look closely at both of them, by interviewing both suppliers and collectors.
The "Restock" use case
Actions that supplier must do every time interval (say, one or two weeks) are: Supplier
unsecures the machine, opens the front of the machine, and fills each brand's compartment
to capacity. (The supplier may fill each brand according to consuming of article). Then he/
she closes the front of the machine and secures it.
The precondition is the passage of the interval, and the postcondition is that the
supplier has a new set of potential sales.
This use case diagram is presented on the following picture:
The Restock use case diagram |
The "Collect Money" use case
Responsible for this use case is collector. Collector may be the same person as the
supplier. The steps that collector must do are same as the steps of supplier, but the
collector don't deal with products, he/ she deals with money. When the time
interval has
passed this person collects the necessary ammount of money from the machine.
The postcondition here is the money in hands of the collector.
Collect money use case diagram is following:
The Collect Money use case diagram |
The steps of unsecuring the machine, front opening, closing and securing the machine
are the same that supplier and collector must do. This is a good place to
include a use
case. Let's combine the "unsecure" and "pull open" steps into use case
called "Expose the inside" and the "close machine" and
"secure" with use case "Unexpose the inside".
By including a use case Restock and Collect use cases may look as this:
The inclusion process in Restock and Collect Money use cases |
The Restock use case could be basis of another use case: "Restock according to
sales". Here supplier may fill up brands with new products according of sale of that
products. This is an extension of a use case.
After inclusion and extension the Restock use case can be:
The extension process in Restock use case |
Also and generalization may take place to the actors supplier and collector. If both of them are the same person, let's say Supplier Agent, then the restocker and the supplier are both children of the Supplier Agent. This is showh on next picture:
A generalization between supplier and collector |
We reached the end of our analysis for the self-service machine. Completed use case diagram (Click for the entirely use case diagram) shows the functional requirements of the system, and we are able to make next move - design and development.