Use Case Sequence Diagram Tutorial
Use Case Sequence Diagram Tutorial
7:R
ATM Card Number, PIN
1 0:
(1) Deposit (2) Withdraw (3) Quit transaction.
Ha n
the ATM card.
equ
dleB
es
6:Welcome Message 5:Welcome Message 40:returns
)
A welcome message is displayed to
t Wit h
nt ry(
an
the user.
kReply ()
ou ntE
dra wa
8 :retu rn s
41:returns
8:Request PIN Box Display 7:Request PIN Request the user to enter the PIN.
9 :returns
dl eA m
ATM Printer Cash Dispenser Display
lAutho
42:returns s
9:Enter PIN 10:Handle PIN Entry The Customer enters the PIN. tu rn
6 : H an
4:re
riza t io
tu rn s
Compare PIN read from the Does the PIN entered by the user 43:returns 12:re
n()
card with the entered PIN match the PIN stored in the card?
LEG: Valid PIN
12:Display Transaction Menu 11:Display Transaction Menu The PIN has matched, so give the
sh()
1 9:
44:Select Transaction Menu User decides to quit. t ()
transaction choices to the user.
re tu
sp enseCa
ri n
3 :P
rn s
13:Select Transaction Menu 14:Handle Transaction Selection User selects the transaction. 45:HandleTransactionSelection()
1 1 :D i
15:create transaction_type
The Session creates the Transaction 5:returns
object. 46:End()
LEG: Cash Deposit into Checking Session 1:CREATE Transaction ction() Logger
Successful ransa
Account ogT
47:PrintReceipt() 14 :L
16 2: S ta rt ( ) ()
17:Enter Cash Amount for deposit 16:Enter Cash Amount for deposit Ask the user to enter the cash :H
an :End ns
dle e tur
20
13
amount for deposit. 48:Print() Tra 1 5: r
18:returns
:DEL
n sa c
ET
18:Cash Amount 19:Cash Amount The customer enters the cash Date/time, Loc, Account, Amount, Balance 17
ti o n
C o m p l e t e ()
E
: r et
amount. u rn s
49:returns
21:Request Cash in Envelope 20:Request Cash in Envelope Request the user to prepare an
envelope with cash.
This tutorial walks you through the development of a simple ATM from use cases to code. The
following stages are covered:
Requirements We start by defining the requirements for a simple ATM that allows the users to
withdraw and deposit cash.
Use Cases The next phase of the design process is to identify the use cases for the system
being developed.
• Identify the Actors: Identify the primary and secondary actors that will
interact with the system.
• Identify the Use Cases: We identify the use cases that provide a good
coverage to the requirements.
• Writing the Use Cases: We now use textual modeling language FDL to
define the use cases. The section also describes modeling of use cases
with sequence diagrams. The following topics are covered:
o Creating a Scenario Project
o Representing the Actors and System Components
o Entering the Use Case Interactions
o Understanding Scenarios
o Adding an Alternative Scenario to the Use Case
o Adding More Scenarios
o Choose the Level of Detail in Sequence Diagrams
o Complete Example
Detailed • Object Sequence Diagrams: The use case diagrams are transformed into
Design object sequence diagrams that define the interactions in terms of public
methods.
• Class Roles and Responsibilities: The next step is to analyze and extract
class design information from the object sequence diagrams. The following
EventStudio diagrams are used in this step:
o Interface Sequence Diagram
o Object Wise Summary
o Interface Collaboration Diagram
2 Requirements
Here are the requirements for building an automated teller machine:
1. The ATM customer interface shall be equipped with a:
a. Magnetic strip card reader for swiping ATM cards.
b. Keypad for user data entry.
c. Display for user feedback.
d. Envelope dispensing slot
e. Printer for printing customer receipts
2. The ATM keypad shall support the following keys:
a. Numbers 0 to 9.
b. “Enter” key to accept the transactions.
c. “Cancel” key to cancel a transaction.
3. The ATM shall communicate to the Bank via the Internet.
4. The ATM shall perform the following authentication steps at the start of a session:
a. The customer shall insert the ATM card.
b. The ATM shall check the card integrity.
c. The customer shall be prompted to enter the personal identification number (PIN).
d. The ATM card number and the PIN shall be authenticated with the bank.
e. The ATM shall abort the session if PIN authentication fails three times. (The PIN
entered should match the PIN specified by the user.)
5. The ATM shall perform the following end of session steps:
a. The ATM card shall not be released at session end if PIN authentication fails.
b. When a transaction ends in error, appropriate error message shall be displayed on
the screen and the machine shall transition to the initial menu.
c. The ATM shall issue a printed receipt to the customer at the end of a successful
session. The receipt shall contain:
• Date and time,
• Machine location,
• Account information,
• Amount of the transaction
• Available balance
6. The ATM shall support the following transactions:
a. Cash withdrawal from checking account.
b. Cash deposit into customer checking account.
7. The ATM shall perform the following transaction verification steps:
a. Cash withdrawal shall be allowed only after the bank permits the transaction.
b. Presence of a cash/check envelope shall be checked before completing the bank
transaction.
c. Cash and check deposits shall be manually verified to ascertain that the amount
entered by the user matches the cash/check value in the deposit envelope.
d. The money transfer between checking and saving shall be verified by the bank.
8. The ATM shall support the following diagnostic features:
a. Logging of all customer interactions
b. Logging of all interactions with the bank
c. The PIN for an ATM card shall not be logged.
3 Use Cases
The first step in the analysis is to develop a better understanding of the requirements by defining
the use case diagrams.
The ATM is the system under design so we scan the requirements to identify entities that interact
with the ATM. The actors have been marked in the requirements with bold-italics-underline.
Customer Customer needs to perform banking transactions using the ATM machine.
Bank The bank serving this ATM.
2. Select the "Starter Scenario Project (Simple)" from the displayed dialog. Then click
"Next".
4. On clicking "Finish", EventStudio will generate and open a sequence diagram in Adobe
Reader. Close this file.
5. Now move to the EventStudio main window and double click on the "Top" icon under the
"Customer_Use_Cases" icon in the left pane (See the following figure). This opens
"Customer_Use_Cases.fdl" file in the main workspace. We will be replacing the
contents of this file in the following steps.
We will decompose the use case entities into a three level hierarchy. At the highest level we have
Actors and the System.
The second level further decomposes the system into smaller subdivisions. The Actors are further
classified as Primary and Secondary Actors. The System is split into Input, Output and Controller.
At the third level we will define eternal and dynamic objects. Eternal objects represent entities that
exist throughout the use case life time. Entities that are instantiated during the use case are
modeled as dynamic objects. Actors identified in section 3.1 are modeled as eternal objects in the
Primary_Actors and Secondary_Actors processors. System components identified in section 3.2
are modeled as eternal and dynamic objects. Note that Session and Transaction are defined as
dynamic objects as they will be created during the use case.
Actors System
Primary Secondary Input Output Controller
Actors Actors
Customer Bank Card Keypad Envelope Display Printer ATM Session Transaction Logger
Reader Dispenser
endfeature
Now replace the contents of Customer_Use_Cases.fdl (see section 3.4.1) with the FDL shown
above.
The next step is to click the "Quick Save and Display" icon (Control-Q is the keyboard shortcut).
EventStudio parses the FDL and generates a sequence diagram similar to the one shown below.
Note that this diagram defines the entities organized hierarchically. An axis is drawn for each
eternal object.
ATM Example: Customer Initiated Use Cases (Hello Goodbye)
Actors System
EventStudio System Designer 4.0
Primary Secondary Input Output Controller
Actors Actors
Customer Bank Card Reader Keypad Envelope Display Printer ATM Session Transaction Logger 28-Aug-07 23:34 (Page 1)
Dispenser
We have defined the architecture of the use case components. The next section describes
modeling of the interactions in the use case diagram.
We scan the requirements in section 1 to specify the interactions involved in setting up an ATM
session followed by a single generic transaction.
The FDL representation of the use case is shown below. We have highlighted some of the
important statements.
chain
"Welcome Message" : Display <- Session
"Welcome Message" : Customer <- Display A message interaction chain
endchain with two messages.
(* A welcome message is displayed to the user. *)
chain
"Request PIN" : Display <- Session
"Request PIN Box Display" : Customer <- Display
endchain
(* Request the user to enter the PIN. *)
chain
"Enter PIN" : Customer -> Keypad
"Handle PIN Entry" : Keypad -> Session
endchain
(* The Customer enters the PIN. *)
Session takes action "Compare PIN read from the card with the entered PIN"
(* Does the PIN entered by the user match the PIN stored in the card? *)
chain
"Display Transaction Menu" : Display <- Session
"Display Transaction Menu" : Customer <- Display
endchain
(* The PIN has matched, so give the transaction choices to the user. *)
chain
"Select Transaction Menu" : Customer -> Keypad
"Handle Transaction Selection" : Keypad -> Session
endchain
(* User selects the transaction. *)
Session object is creating a
heading "General handling for a transaction" dynamic Transaction object.
Session creates Transaction
(* The Session creates the Transaction object. *)
chain
"Select Transaction Menu" : Customer -> Keypad
"Handle Transaction Selection" : Keypad -> Session
endchain
(* The user makes a selection. In this case, the user decides to end the
session. *)
endfeature
The next step is to click the "Quick Save and Display" icon (Keyboard: Control-Q). EventStudio
will generate a PDF sequence diagram similar to the one shown below. You can see the
representation of the highlighted FDL statements in the sequence diagram.
Session object 1:Eject ATM Card Eject the ATM card as the session has
been completed successfully.
takes an action. 2:Session Log Update the session level log.
3:Session Complete Notify the ATM object.
4:delete ATM deletes the Session object.
The scenario is represented in the left side scenario bar as shown below. EventStudio template
we used created a default scenario called "Hello Goodbye". Let's rename this scenario to "Valid
PIN" by right-clicking on the Scenario and selecting the "Rename Scenario" command.
This scenario will serve as our successful case scenario. Addition of case-leg-endcase
statements will result in modification to this scenario to select the case-legs that apply to this
scenario.
The new scenario is added by simply introducing a case-endcase block with leg statements for
valid and invalid PIN scenarios.
"Credit Card Swipe" ("ATM Card Number", PIN) : Card_Reader -> ATM
(* The Card Reader in the ATM detects the credit card and sends a message to
the ATM object. *)
chain
"Welcome Message" : Display <- Session
chain
"Enter PIN" : Customer -> Keypad The "Invalid PIN" retries PIN
"Handle PIN Entry" : Keypad -> Session entry and swallows the ATM
endchain card on repeated failures.
(* The Customer enters the PIN. *)
Session takes action "Compare PIN read from the card with the entered PIN"
(* Does the PIN entered by the user match the PIN stored in the card? *)
case
leg "Valid PIN": A block remark
chain
"Enter PIN" : Customer -> Keypad
"Handle PIN Entry" : Keypad -> Session
endchain
[* End Loop: Retry PIN *]
chain
"Display Transaction Menu" : Display <- Session
"Display Transaction Menu" : Customer <- Display
endchain
(* The PIN has matched, so give the transaction choices to the user. *)
...Other Statements...
endfeature
Now let's save and regenerate the use case diagram by Control-Q (Quick Save and Display).
EventStudio senses the new case statement and asks us to make the leg selection for the
existing Scenario ("Valid PIN"). We select "Valid PIN" leg for the "Valid PIN" Scenario.
Once the selection is made, EventStudio associates the case leg "Valid PIN" with the "Valid PIN"
scenario.
We will now add a second scenario for the case where the user enters an invalid PIN. The steps
involved here are:
2. Enter the Scenario title "Customer Enters an Invalid PIN" and click "Next".
Click "Next"
3. Select the "Customer_Use_Cases.fdl" file and click "Next".
Click "Next"
Click "Next"
Click "Finish"
6. EventStudio now displays two Scenarios in the left pane. The legs uniquely identifying
the Scenarios are also listed.
7. Now click the "Review All Scenarios" icon (Control-W) to look for design errors.
Perform a design
review by clicking the
"Review All Scenarios"
icon.
label exit:
EventStudio had detected that the
"Session Log" : Session -> Logger Session object was not being
(* Update the session level log. *) deleted in the "Invalid PIN" leg.
"Session Complete" : ATM <- Session
(* Notify the ATM object. *) We fix the problem by moving the
exit label. This ensures that the
ATM deletes Session Session is deleted correctly in all
(* ATM deletes the Session object. *) cases.
endfeature
9. Now click Control-Q to save and generate the documents. EventStudio generates a
combined use case diagram that includes two Scenarios.
The scenario support is added in the FDL is via a case-endcase statement. An important point to
note here is the use of #includes and #define-macros to simplify the FDL.
Once the scenarios have been added type "Control+Q" to update the sequence diagram.
/* == inc.fdl == */
#include "inc.fdl"
Include the "inc.fdl" defined above.
/* Customer Use Cases */
...Other Declarations...
...Other Statements...
"Authorize Cash Withdrawal"("ATM card #", PIN, Amount): Bank <- Transaction
(* Request the Bank to authorize the cash withdrawal. *)
Bank takes action "Validate the ATM card, PIN and check Amount availability"
(* The Bank validates the transaction. *)
TRANSACTION_OUTPUT("Cash", Cash_Dispenser)
(* Dispense the cash to the user. *)
...Other Statements...
endfeature
3:Eject ATM Card Eject the ATM card as the session has been completed successfully.
4 Detailed Design
The first phase of analysis and design has been completed with the generation of detailed use
case diagrams. We will now focus on the detailed design.
6. We go through the use case diagram and convert the message interactions into method
invocation. The structure of the FDL is also changed. More details are added. The new
FDL file is shown below1:
#include "inc.fdl"
module : System
processor : ATM_Controller in System
eternal : Bank in ATM_Controller
eternal : Card_Reader in ATM_Controller
eternal : Keypad in ATM_Controller
eternal : Envelope_Slot in ATM_Controller
eternal : Display in ATM_Controller The customer has been
eternal : Cash_Dispenser in ATM_Controller represented as an environment.
eternal : Printer in ATM_Controller FDL supports env_l and env_r as
eternal : ATM in ATM_Controller
dynamic : Session in ATM_Controller the left and right environment.
dynamic : Transaction in ATM_Controller
eternal : Logger in ATM_Controller
1
The complete example can be downloaded from [TBD].
EventStudio System Designer 4.0 24
© Copyright EventHelix.com Inc. All rights reserved.
Use Case and Sequence Diagram Tutorial Detailed Design
Session takes action "Compare PIN read from the card with the entered PIN"
(* Does the PIN entered by the user match the PIN stored in the card? *)
case
leg "Valid PIN":
endcase
Transaction invokes Transaction.End
Transaction invokes Logger.LogTransaction("Log entry")
Logger.LogTransaction returns
Session.HandleTransactionComplete returns
Transaction.End returns
label exit:
endfeature
7. Click Control-Q to regenerate the sequence diagram. A page from the generated
sequence diagram is shown below:
ATM Example: Customer Initiated Use Cases (Cash Withdrawal from Checking)
System
EventStudio System Designer 4.0
ATM Controller
Bank Card Reader Keypad Envelope Slot Display Cash Printer ATM Session Transaction Logger 30-Sep-07 11:43 (Page 3)
Dispenser
34:returns
35:End()
36:LogTransaction()
Log entry
37:returns
38:HandleTransactionComplete()
41:returns
42:returns
43:returns
Successful
47:PrintReceipt()
48:Print()
Date/time, Loc, Account, Amount, Balance
49:returns
Interface Sequence Diagrams A sequence diagram that just lists the interactions
involving one module, processor or object.
Summary Document Object wise summary of the interactions. The HTML
document lists the interactions on a per object basis.
Interface Collaboration Diagrams A collaboration diagram that just lists the interactions
involving one module, processor or object.
Click "Finish"
7. Now right click on the "Session Sequence Diagram" in the left pane and select "Generate
Document" from the popup menu.
8. EventStudio generates the document and opens the document. One of the pages of the
generated document is shown below.
Session Interfaces (Cash Withdrawal from Checking)
System
EventStudio System Designer 4.0
ATM Controller
Bank Card Reader Keypad Envelope Slot Display Cash Printer ATM Session Transaction Logger 23-Sep-07 23:05 (Page 1)
Dispenser
1:create The ATM object has detected the start
of a new session. The ATM object
creates a new Session object.
2:Start() Update the Session object with the
cardNumber, pin ATM card # and PIN stored on the ATM
card.
3:Print() A welcome message is displayed to the
Welcome to the XYZ Bank ATM user.
4:returns
6:returns
7:returns
8:HandlePIN()
pin
Compare PIN read from the card Does the PIN entered by the user
with the entered PIN match the PIN stored in the card?
LEG: Valid PIN
9:Print() The PIN has matched, so give the
(1) Deposit (2) Withdraw (3) Quit transaction choices to the user.
10:returns
11:returns
12:HandleTransactionSelection()
transaction_type
LEG: Cash Withdrawal from
Checking Account
13:create The Session creates the
WithdrawCashTransaction object.
14:Start()
Legs Taken:
• Valid PIN
• Cash Withdrawal from Checking Account
Bank Actions
Card_Reader Actions
Keypad Actions
Display Actions
System
ATM Controller
10:
H
equ
a nd
es t W
leB a n
y()
tEntr
it h d ra
kReply()
8:returns
m ou n
walAu
9:re turn s
t urns
4:re
6 :H a
a t io n
tu rns
12:re
()
sh()
19:
t( )
r e tu
ispenseCa
r in
3 :P
r ns
1 1 :D
5:returns
Tra 1 5 :r
18:returns
:DE
ns
a ct
LE
io n C )
o m p l e te (
TE
17
:r e
tu rn
s
2
We have generated these class diagrams with Visual Studio 2005. You may use any freeware
of commercial UML tool to generate the class diagrams.
EventStudio System Designer 4.0 33
© Copyright EventHelix.com Inc. All rights reserved.
Use Case and Sequence Diagram Tutorial Detailed Design
Session
Session
Class
_transaction
CashDispenser CardReader
Class Abstract Class Class
CashDispenser CardReader
DepositCashTransaction WithdrawCashTransaction
Class Class
Transaction Transaction
Printer Logger
EnvelopeSlot
KeyPad Display
Keypad EnvelopeSlot Display
Class Class Class
Bank Bank
Class
The ZIP file also contains the Use Case and Detailed Design Scenario Projects.