Introduction Use Case Diagram Class Diagram Sequence Diagram Unified Modeling Language (UML) Miaoqing Huang University of Arkansas 1 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Unified Modeling Language (UML)
Miaoqing HuangUniversity of Arkansas
1 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Outline
1 Introduction
2 Use Case Diagram
3 Class Diagram
4 Sequence Diagram
2 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Outline
1 Introduction
2 Use Case Diagram
3 Class Diagram
4 Sequence Diagram
3 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
What is UML?
UML is a modeling languageA model is an abstraction describing a systemModeling language is used to express design
Use notation for depicting models
UML is the de facto modeling language in software engineeringCreated and managed by the Object Management Group, now atversion 2.4.1 (August 2011)Key persons: (three amigos) James Rumbaugh, Grady Booch,Ivar Jacobson
UML includes a set of graphical notation techniques to createvisual models of software-intensive systems
14 diagrams7 structural diagrams7 behavior diagrams
4 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
UML Diagrams
5 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
UML Diagrams – Example
use case diagram class diagram sequence diagram
6 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
UML Diagrams – Example
Use case diagramDescribe the functional behavior of the system as seen by theuser
Class diagramDescribe the static structure of the system: Objects, attributes,associations
Sequence diagramDescribe the dynamic behavior between objects of the system
State machine diagramDescribe the dynamic behavior of an individual object
7 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
UML Core Conventions
All UML Diagrams denote graphs of nodes and edgesNodes are entities and drawn as rectangles or ovalsRectangles denote classes or instances
Ovals denote functionsNames of Classes are not underlined
SimpleWatchFirefighter
Names of Instances are underlinedmyWatch:SimpleWatchJoe:Firefighter
An edge between two nodes denotes a relationship between thecorresponding entities
8 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Use Case Diagram
Use case diagrams represent the functionality of the systemfrom user’s point of view
WatchUser
Actor
Use case
ReadTime
SetTime
ChangeBattery
WatchRepairPerson
9 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Class Diagram
Class diagrams represent the structure of the system
12
push()release()
1
1
blinkIdxblinkSeconds()blinkMinutes()blinkHours()stopBlinking()referesh()
LCDDisplay BatteryLoad
1
2
1
TimeNow
1
Watch
Operations
statePushButton
Attribute
ClassAssociation
Multiplicity
10 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Sequence Diagram
Sequence diagrams represent the behavior of a system asmessages (“interactions”) between different objects
Message
:Time:Watch:WatchUser
Object
Activation
Actor
pressButton1()
Lifeline
blinkHours()
pressButton2()incrementMinutes()
:LCDDisplay
pressButton1and2()commitNewTime()
stopBlinking()
refresh()
pressButton1()blinkMinutes()
11 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
State Machine Diagram
State machine diagrams represents behavior of a single objectwith interesting dynamic behavior
State
Initial state
Final state
Transition
Event
button1&2Pressed
button1Pressed
button2Pressed
button2Pressed
button2Pressed
button1Pressed
button1&2Pressed IncrementMinutes
IncrementHours
BlinkHours
BlinkSeconds
BlinkMinutes
IncrementSeconds
StopBlinking
12 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Outline
1 Introduction
2 Use Case Diagram
3 Class Diagram
4 Sequence Diagram
13 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
What is a use case?
ScenarioA sequence of steps describing an interaction between a user anda system
The customer browse the catalog and adds desired items to the shoppingbasket. When the customer wishes to pay, the customer describes theshipping and credit information and confirms the sale. The systemchecks the authorization on the credit card and confirms the sale bothimmediately and with a follow-up email.
Use caseA use case is a set of scenarios tied together by a common usergoal
Buy a Product use case: a successful purchase or authorizationfailure
14 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Describe a use case
A set of scenarios in the Use Case “Buy a product online”:1. Customer browses through catalog and selects items to buy2. Customer goes to check out3. Customer fills in shipping information4. System presents full pricing information, including shipping5. Customer fills in credit card information6. System authorizes purchase7. System confirms sale immediately8. System sends confirming email to customer
15 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
An Example
uc Use Cases
System Boundary
OrderFood
CookFood
OrderWine
ServeFood
ServeWine
EatFood
DrinkWine
Pay forFood
Pay forWine
Waiter
Chef
Client
Cashier
receive order
confirm order
facilitate payment
pay
accept
payment
place order
<<extend>> {if wine was ordered}
<<extend>>
<<extend>>
{if wine was
served}
<<extend>>{if wine
was consumed}
16 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Actor and Use Case
An actor is a role that a user play with respect to thesystemActors are connected to the use cases by a line
A single actor may perform many use casesA use case may have several actors performing it
Four types of relationships in use case diagramGeneralization between use casesGeneralization between actorsInclude relationship between use casesExtend relationship between use cases
17 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Generalization between use cases
Different versions of a use case share some actions in commonand have some that are unique to each one
Generalized use case: abstract use caseIt may never exist in a real system
Specialized use case: concrete use case
Pay utility bill
18 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Generalization between Actors
Specialized actor can do everything the generalactor can do, and more
19 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Generalization between Actors
Specialized actor can do everything the generalactor can do, and more
20 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Generalization between Actors
Specialized actor can do everything the generalactor can do, and more
21 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Include Relationship between Use Cases
One use case includes the functionality of another use caseInvocation of one use case by another one
e.g., calling a function or invoking an operation within source code
22 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Extend Relationship between Use Cases
One use case may be extended by the functionality in anotheruse case
23 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Include, Generalization, Extend
IncludeUse include when you are repeating yourself in two or moreseparate use cases and you want to avoid repetition
GeneralizationUse Generalization when you are describing a variation on normalbehavior and you wish to describe it casually
ExtendUse extend when you are describing a variation on normalbehavior and you wish to use the more controlled form, declaringyour extension points in your base use case
24 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Outline
1 Introduction
2 Use Case Diagram
3 Class Diagram
4 Sequence Diagram
25 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Class Diagram
Class diagrams show the static structure of the classes thatmake up a system or subsystemUse case diagrams show the functional requirements of a system(or subsystem) from the perspective of the end-user of a system
26 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Classes
Classes are shown as rectanglesClass nameOther compartments
AttributesOperationsOther predefined compartments
Name conventionClass’ name
Have no space between multiple wordsCapitalize the first letter in eachsubsequent world
Name of features in compartmentsHave no space between multiple wordsCapitalize the first letter in eachsubsequent world except the first world
27 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Associations among classesAssociations represent relationships between(instances of) classes
Classes collaborate with each other by passingmessages and receiving responses
Association nameIndicates the nature of the associationAssociate name should begin with a capital letterNavigability: use arrow to indicate how to interpretthe association
Unidirectional associationBidirectional association: without arrow
Role nameIndicate the role played by a class in anassociationAttached to the corresponding association endCan use the same rule of naming features to namethe role, i.e., low case the very first letter andcapitalize the first letter of subsequent word
28 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Multiplicity
Multiplicity indicates how many objects may participate in thegiven relationship (during the run-time of your software system)
*: 0..infinity1: 1..1n..m: low_bound..up_bound
Multiplicity of an association end is not shownThe multiplicity is not knownThe multiplicity is not specified
29 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Aggregation
Aggregation symbol.Assembly consists of components.Component is part of an assembly
Aggregation associationAn instance of one class may consist of instances of another classwhole-part association
whole is made up of partsUse a solid line with an unfilled diamond shape at the end
Diamond is connected to the class that is the aggregateA part is capable of existing outside of whole-part association
30 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Composition
Document
SectionFrontMatter Index1 0..1
0..11..*
1..*
Document
FrontMatter [1]
Section [1..*]
Index [0..1]0..1
1..*
Composition associationwhole-part association
The life-cycle of the ‘part’ cannot extend beyond the life-cycle of the‘whole’
Two different notationsFilled diamond notationGraphical containment
31 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Generalization
Generalization relationship is(sometimes) described as being a kindof relationship
Generalized class: superclass(supertype)Specialization: subclass (subtype)
Generalization allows the inheritance ofthe attributes and operations of asuperclass by its subclasses
Subclass can override the operations inthe superclass
32 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
More on attribute and operation
Attribute and Operation Typesfeature-name : type
Attribute and Operation Visibilityprivate (-)
The feature is available only within the class that owns the featurepublic (+)
The feature is available to any class associated with the class thatowns the feature
protected (#)The feature is available within the class that owns that feature andany subtype of that class
package (∼)The feature is available only to other classes in the same package
33 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Outline
1 Introduction
2 Use Case Diagram
3 Class Diagram
4 Sequence Diagram
34 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Purpose of Sequence Diagram
Static diagramUse case diagrams show the static relationship between actorsand use casesClass diagrams show the static relationship between classes orinstances
A program is a sequence of interactions among objects (i.e.,instances of classes)
Difficult to understand a program only with static diagramsPurpose of sequence diagram
Model the high-level interactions between active objects in asystemModel the high-level interactions between subsystems
35 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Sequence Diagram Example
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
36 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
NotationFrame
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
Sequence diagrams aredrawn in frames
New in UML 2.0
Time runs verticallyLifelines are arrangedhorizontally
Represent object instances
37 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
NotationFrame
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
Sequence diagrams aredrawn in frames
New in UML 2.0
Time runs verticallyLifelines are arrangedhorizontally
Represent object instances
38 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
NotationLifeline
Participating instances are represented bylifelines
Dashed vertical lineRectangle representing an object
Syntax Explanationo An object named oo : C An object named o of class C:C An anonymous object of class C
39 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
NotationMessages and Activation box
A message is shown using an arrow going from the sender to thereceiver
Different types of messagesSynchronous
The sender waits until the reply is receivedAsynchronous
The sender does not wait for the reply; instead, it carries on the nextstep in its own sequence
CreationA message causes the creation of an object instance to which themessage is sent
Reply
40 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
NotationMessages and Activation box
A message is shown using an arrow going from the sender to thereceiverDifferent types of messages
SynchronousThe sender waits until the reply is received
AsynchronousThe sender does not wait for the reply; instead, it carries on the nextstep in its own sequence
CreationA message causes the creation of an object instance to which themessage is sent
Reply
41 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Sequence Diagram Example with Explicit Reply
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
42 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
NotationCombined Fragments
A sequence of messages can be combined into a fragmentLoop, branches, ...
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
43 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
NotationCombined Fragments
:ReliableDistributor:Order
dispatch
loop [ for each item ]
:NormalDistributor
dispatch
alt [ value > $10,000 ]
[ else ]
44 / 45
Introduction Use Case Diagram Class Diagram Sequence Diagram
Exercise
Lay out the lifelines for instances of the classes Student, EnrollInSeminar,SecurityLogon, StudentDatabase, and Seminar. Add the followingmessages to the diagram. Note, keep the order of the messages.
1 Request to enroll to seminar A2 Create an instance of SecurityLogon class3 Provide name4 Provide student number5 Provide password6 Verify the student (name, number, password)7 Return verification result8 Return the student information9 Add the student into the seminar A10 Confirmation of enrollment of seminar A11 Display the confirmation to student
Note: EnrollInSeminar class is both the main control and the main interfacewith the student
45 / 45