Escolar Documentos
Profissional Documentos
Cultura Documentos
• Functionality
– Use-case diagrams
• Decomposition
– Class diagrams (class structure)
– Package diagrams, Deployment diagrams (architecture)
• Behavior
– State diagrams, Activity diagrams
• Communication
– Sequence diagrams, Collaboration diagrams
Use Cases and Use Case Diagrams
• References
– “Getting started: Using use cases to capture requirements”, James
Rumbaugh, 1994
– “Using UML”, Perdita Stevens, Rob Pooley, 2000
• Use cases document the behavior of the system from the users’ point
of view.
– By user we mean anything external to the system
– It can be another software system interacting with the software
system being specified
Actors in Use Cases
• An actor is a role played by an outside entity that interacts directly
with the system
Librarian
Use Cases
• A use case describes the possible sequences of interactions among the
system and one or more actors in response to some initial stimulus by
one of the actors
– Each way of using the system is called a use case
– A use case is not a single scenario but rather a description of a set
of potential scenarios
– For example: Installing a Database, Adding a New User to the
Database
– Individual use cases are shown as named ovals in use case
diagrams
Installing
a Database
Use Cases
• A use case involves a sequence of interactions between the initiator
and the system, possibly involving other actors.
• A typical use case might include a main case, with alternatives taken
in various combinations and including all possible exceptions that can
arise in handling them
– For example Check in for Flight use case uses Assign Seat use
case
– In the extends the extended use case is a valid use case by itself
– In the uses the use case which is using the other use case is not
complete without it
Use Case Diagrams: Combining Use Cases
<<uses>> Check in
Assign Seat for Flight
<<extends>>
<<extends>>
Upgrade
Check use case
Seat
Flight Attendant Baggage
actor
Customer
Defining Use Cases
• Identify the boundary of the application, identify the objects outside
the boundary that interact with the system
• Classify the objects by the roles they play, each role defines an actor
• Consider all the exceptions that can occur and how they affect the use
case
• Look for common fragments among different use cases and factor
them out into base cases and additions
Documenting Use Cases
Use case: Place Order
Actors: Costumer
Precondition: A valid user has logged into the system
Flow of Events:
1. The use case begins when the customer selects Place Order
2. The customer enters his or her name and address
3. If the customer enters only the zip code, the system supplies the city and state
4. The customer enters product codes for products to be ordered
5. For each product code entered
a) the system supplies a product description and price
b) the system adds the price of the item to the total
end loop
6. The customer enters credit card payment information
7. The customer selects Submit
8. The system verifies the information [Exception: Information Incorrect], saves the order as pending, and forwards
payment information to the accounting system.
9. When payment is confirmed [Exception: Payment not Confirmed], the order is marked confirmed, an order ID is
returned to the customer, and the use case terminates
Exceptions:
Payment not Confirmed: the system will prompt the customer to correct payment information or cancel. If the customer
chooses to correct the information, go back to step 6 in the Basic Path. If the customer chooses to cancel, the use case
terminates.
Information Incorrect: If any information is incorrect, the system prompts the customer to correct it.
Postcondition: If the order was not canceled, it is saved in the system and marked confirmed
Documenting Use Cases
Flow of Events:
Basic Path:
1. The use case begins when the customer selects Place Order
2. The customer enters his or her name and address
3. While the customer enters product codes
a) the system supplies a product description and price
b) the system adds the price of the item to the total
end loop
6. The customer enters credit card payment information
7. The customer selects Submit
8. The system verifies the information [Exception: Information Incorrect], saves the order as pending, and
forwards payment information to the accounting system.
9. When payment is confirmed [Exception: payment not confirmed], the order is marked confirmed, an order ID is
returned to the customer, and the use case terminates
Alternative Paths:
– At any time before selecting submit, the customer can select Cancel. The order is not saved and the use case
ends
– In step 6, if any information is incorrect, the system prompts the customer to correct the information
– In step 7, if payment is not confirmed, the system prompts the customer to correct payment information or
cancel. If the customer chooses to correct the information, go back to step 4 in the Basic Path. If the
customer chooses to cancel, the use case ends.
Online Human Resources (HR) System
system
Online HR System boundary
Locate
Employee
Manager
Update Employee
Profile
Access Travel
System
[read only access]
Access Pay
Records
Employee Account Insurance Plan
Database System
Online HR System
Use case: Update Benefits
Actors: Employee, Employee Account Database, Healthcare Plan System, Insurance Plan
System
Precondition: Employee has logged on to the system and selected “update benefits” option
Flow of Events:
Basic Path:
1. System retrieves employee account from Employee Account Database
2. System asks employee to select medical plan type; uses Update Medical Plan
3. System asks employee to select dental plan type; uses Update Dental Plan
...
Alternative Paths:
If health plan is not available in the Employee’s area the employee is informed and
asked to select another plan
Online HR System
Update
Dental Plan Update
Update Insurance Plan
Medical Plan
<<uses>> <<uses>>
<<uses>>
Update Benefits
Extension Points extension point name
Benefits Options: after extension location
required enrollments
Employee
<<extends>>(Benefits Options)
[employee requests
<<extends>> (Benefits Options) stock purchase option]
[employee requests
reimbursement option]
Select Stock
Purchase
Select Reimbursement
for Healthcare
Generalization in use case diagrams
Validate
Customer User
Check Retinal
Password Scan
Corporate
Individual Customer
Customer
UML Class Diagrams
• Class diagram describes
– Types of objects in the system
– Static relationships among them
Operations +creditRating():String
Visibility:
public + (default) any outside class with visibility to the given class can use the feature
protected # any descendant of the class can use the feature
private – only the class itself can use the feature
remind()
billForMonth(Int)
Constraints
• Represent further restrictions on associations or classes
• They are stated inside braces {} and there is no formal syntax for
them in UML
• Object Constraint Language (OCL) is a formal language for
specifying constraints
Order Customer
dateReceived
isPrepaid 1..* 1 name
number: String address
price: Money
creditRating():String
dispatch() Constraint
close() for order class
{If Order.customer.creditRating
is “poor”, then Order.isPrepaid
must be true}
Example Class Diagram
Order Customer
dateReceived 1..* 1 name
isPrepaid address
number: String
price: Money creditRating():String
dispatch() Constraint indicates
close() for order class generalization
1
Order
1 1
shows shows
aggregation 1 composition
1 1
Shipping Billing
Information Information
1..*
Book
Qualified Associations
• Association can be keyed by the value of the qualifier
Order qualifier
dateRecieved
isPrepaid Product Order
number: String 0..1 quantity: Int
Product
price: Money Ordered price: Money
dispatch() Product isSatisfied: Bool
close()
Association Classes
• Adds attributes and operations to an association
– Allows exactly one instance of the association class between any
two objects
– Can use an actual class instead, if you need more
0..* 1..*
Company Person
employer employee
Job
description
dateHired
salary
Sequence Diagrams
• A sequence diagram shows a particular sequence of messages
exchanged between a number of objects
• Sequence diagrams can be used to generate test cases for the software
product
• Lifeline Object
– dashed line, represents
time flow
Lifeline
Components of Sequence Diagrams
• Messages
– communication between :ProductOrder :StockItem
objects
– method calls at the Message
implementation level check()
needsToReorder()
• Special message types
– self-delegation
Self-delegation
– return
• show returns only if it
adds to clarity Return
– <<create>>
– <<destroy>>
Components of Sequence Diagrams
• Two kinds of control
information: :Order :ProductOrder :StockItem
prepare()
*prepare()
check()
[check=“true”]
remove()
needsToReorder()
[needsToReorder=“true”]
<<create>>
:ReorderItem
[check=“true”]
<<create>> :DeliveryItem
Sequence diagrams
• Show conditional behavior on separate diagrams to keep them
understandable
– for example for a use case you can give the basic path as one
sequence diagram and have separate sequence diagrams for
alternative paths or exceptions
lifeline
Collaboration Diagrams
prepare()
*prepare()
check()
[check=“true”]
remove()
needsToReorder()
[needsToReorder=“true”]
<<create>>
:ReorderItem
[check=“true”]
<<create>> :DeliveryItem
Corresponding Collaboration Diagram
object
:OrderEntryWindow
1:prepare() message
link sequence number
:Order
1.1.2.1:needsToReorder()
1.1:*prepare()
:ProductOrder :StockItem
1.1.1:check()
1.1.2:[check==true]remove() 1.1.2.2:new
1.1.3:[check==true]new :DeliveryItem
:ReorderItem
State Diagrams
• State diagrams are used to show possible states a single object can get
into
– shows states of an object
Tracking
entry action
entry / setMode(on Track)
exit action exit / setMode(off Track)
internal transition newTarget / tracker.Acquire()
do / followTarget
activity selfTest / defer
deferred event
/ getFirstItem
getNextItem Checking
[not all items checked]
do / checkItem
cancelled
/ getFirstItem
itemsReceived
[some items not in stock]
cancelled
Waiting Delivered
cancelled
Cancelled
Active is a superstate
State Diagrams: Superstates with substates Checking,
Waiting and Dispatching
/ getFirstItem Active
itemsReceived
[some items not in stock]
Waiting
cancelled
Cancelled Delivered
State Diagrams: Concurrent states
• Payment authorization is done concurrently with the order processing
Authorizing
[payment not OK]
do/check Rejected
Payment
[payment OK]
Authorized
Delivered
State Diagrams: Concurrent States
cancelled
Waiting
Cancelled
Checking Dispatching
Delivered
Authorizing Authorized
this transition
can only be taken
after both concurrent
states reach their
final states
[payment not OK] Rejected
State Diagrams
• Good at describing behavior of an object across several use-cases
• Use them to show the behavior of a single object not many objects
– for many objects use interaction diagrams
• Do not try to draw state diagrams for every class in the system, use
them to show interesting behavior and increase understanding
Activity Diagrams
• Activity diagrams show the flow among activities and actions
associated with a given object using:
– activity and action states
– transitions
– branches
– merges
– forks
– joins
• Activity diagrams are derived from SDL state diagrams, SDL state
diagrams have formal semantics
Activity Diagrams
• Activity
– represents a task that has to be performed, a non-atomic execution
within a state machine
– from an implementation perspective it can represent a method
• Action
– an atomic computation that changes the state of the system or
returns a value
Activity Diagrams
• When an activity or action of a initial state
state is completed the control
passes immediately to the next
action or activity state
Receive
Supply
action or
• Transitions can have guard activity states
transition
conditions
Choose Outstanding
Order Item
• Multiple trigger symbol * is
used to show iteration * for each chosen
order item
Assign Goods
in Order
Activity Diagrams: Branches
• Conditional branches
– correspond to if-then-else or switch
statements at the implementation level
• a branch is shown as a diamond
Authorize
• a branch can have one incoming transition
guard Payment
and two or more outgoing expressions
• the guard conditions on different outgoing
transitions should not overlap to prevent branch
nondeterminism [succeeded]
• guard conditions on different outgoing
transitions should cover all the possibilities
so that the control flow does not get stuck at [failed]
the branch
join
Dispatch
Order
Finance Order Stock
Processing Manager
ReceiveSupply
Receive Order
*for each
order item Choose Outstanding vertical lines
Order Items are used to separate
Authorize Check Order
“swimlanes”
Payment Item
* for each to show which
[in stock] chosen activities are handled
[failed] order item by which part of the
Assign to Order system
Assign to
Cancel Order
[succeeded]
Order
[need to reorder]
Reorder
item
[all outstanding order
items filled]
• Functionality
– use case diagrams
• Decomposition
– class diagrams (class structure)
– package diagrams, deployment diagrams (architecture)
• Behavior
– state diagrams, activity diagrams
• Communication
– sequence diagrams, collaboration diagrams