08 - Modeling With UML
08 - Modeling With UML
Lecture 8
What is modeling?
What is UML?
Use case diagrams
Class diagrams
Sequence diagrams
Activity diagrams
What is modeling?
Object-oriented Modeling
Application Domain
(Phenomena)
Solution Domain
(Phenomena)
TrafficControl
UML
Package
Aircraft TrafficController
Airport
FlightPlan
Summary
MapDisplay Display
FlightPlanDatabase
TrafficControl
6
What is UML?
UML (Unified Modeling Language)
Nonproprietary standard for modeling software systems,
OMG
Convergence of notations used in object-oriented methods
OMT (James Rumbaugh)
Booch (Grady Booch)
OOSE (Ivar Jacobson)
Commercial tools:
(business processes)
Class diagrams
Describe the static structure of the system: Objects,
attributes, associations
Sequence diagrams
Describe the dynamic behavior between objects of
the system
State diagrams
Describe the dynamic behavior of an individual
object
9
SimpleWatch
Firefighter
myWatch:SimpleWatch
Joe:Firefighter
Use Case
Actor
System boundary
Use case diagrams represent the functionality of the system from users point of view
11
SimpleWatch
1
1
Display
1
2
Battery
1
Time
Attribute
Watch
1 1 1
1
LCDDisplay
blinkIdx
blinkSeconds()
blinkMinutes()
blinkHours()
stopBlinking()
referesh()
2
Battery
Load
1
Time
Now
Operations
13
Message
:WatchUser
Object
:Watch
pressButton1()
pressButton1()
pressButton2()
Lifeline
:LCDDisplay
:Time
blinkHours()
blinkMinutes()
incrementMinutes()
refresh()
pressButton1and2()
commitNewTime()
Activation
stopBlinking()
14
Initial state
Event
button1&2Pressed
Transition
button1&2Pressed
State
Blink
Hours
button2Pressed
Increment
Hours
button1Pressed
Blink
Minutes
button2Pressed
Increment
Minutes
button1Pressed
Stop
Blinking
Blink
Seconds
button2Pressed
Increment
Seconds
Final state
Represent behavior of a single object with interesting dynamic behavior.
15
Reverse Engineering
Creation of a model from existing code
Interface or reengineering projects
Roundtrip Engineering
Move constantly between forward and reverse
engineering
Reengineering projects
Useful when requirements, technology and schedule are
changing frequently.
17
Class diagrams
Describe the static structure of the system: Objects,
attributes, associations
Sequence diagrams
Describe the dynamic behavior between objects of the
system
State diagrams
Describe the dynamic behavior of an individual object
Activity diagrams
Describe the dynamic behavior of a system, in particular
the workflow.
18
Passenger
PurchaseTicket
Actors
An actor is a model for an external
entity which interacts
(communicates) with the system:
User
External system (Another system)
Physical environment (e.g. Weather)
Passenger
Name
20
Use
Case
A use case represents a class
PurchaseTicket
of functionality provided by
the system
Use cases can be described
textually, with a focus on the
event flow between actor and
system
The textual use case
description consists of 6 parts:
1.Unique name
2.Participating actors
3.Entry conditions
4.Exit conditions
5.Flow of events
21
PurchaseTicket
Passenger
5. Flow of events:
1. Name: Purchaseticket
2. Participating actor:
Passenger
3. Entry condition:
Passenger stands in front
of ticket distributor
Passenger has sufficient
money to purchase ticket
4. Exit condition:
Passenger has ticket
6. Special requirements:
None.
22
Extends Relationship
To represent seldom invoked use cases
or exceptional functionality
Includes Relationship
To represent functional behavior
common to more than one use case.
23
Passenger
PurchaseTicket
<<extends>>
<<extends>>
<<extends>> relationships
model exceptional or seldom
invoked cases
The exceptional event flows
are factored out of the main
event flow for clarity
The direction of an
<<extends>> relationship is to
the extended use case
Use cases representing
exceptional flows can extend
more than one use case.
<<extends>>
OutOfOrder
<<extends>>
Cancel
NoChange
TimeOut
24
The <<includes>>Relationship
<<includes>>
relationship represents
common functionality
needed in more than one
Passenger
use case
<<includes>> behavior
PurchaseMultiCard
is factored out for reuse,
not because it is an
PurchaseSingleTicket
exception
<<includes>>
The direction of a
<<includes>>
<<includes>>
relationship is to the
using use case (unlike
CollectMoney
the direction of the
<<extends>>
<<extends>>
<<extends>>
relationship)
NoChange
Cancel
25
Class Diagrams
TarifSchedule
Tablezone2price
EnumerationgetZones()
PricegetPrice(Zone)
Trip
zone:Zone
* price:Price
26
Classes
Type
Name
TarifSchedule
zone2price
getZones()
getPrice()
TarifSchedule
Tablezone2price
EnumerationgetZones()
PricegetPrice(Zone)
Attributes
Signature
Operations
TarifSchedule
Actor
An entity outside the system to be modeled,
interacting with the system (Passenger)
Class
An abstraction modeling an entity in the
application or solution domain
The class is part of the system model (User,
Ticket distributor, Server)
Object
A specific instance of a class (Joe, the
passenger who is purchasing a ticket from the
ticket distributor).
29
Associations
TarifSchedule
TripLeg
EnumerationgetZones()
PricegetPrice(Zone)
Price
Zone
name:String
1 Capital(City)
name:String
1to1association
Polygon
Point
x: Integer
y: Integer
draw()
1tomanyassociation
31
Many-to-Many Associations
Company
StockExchange
tickerSymbol
32
Class Diagram:
StockExchange
*
Lists
Company
tickerSymbol
33
Java Code
*
Lists
Company
tickerSymbol
publicclassStockExchange
{
privateVectorm_Company=newVector();
};
Associations
are mapped to
Attributes!
publicclassCompany
{
publicintm_tickerSymbol;
privateVectorm_StockExchange=newVector();
};
34
Aggregation
0..2
Muffler
Tailpipe
diameter
diameter
Qualifiers
Without qualification
Directory
File
filename
With qualification
Directory
filename
0..1
File
StockExchange
Lists
tickerSymbol
Lists
tickerSymbol
Company
37
Inheritance
Button
CancelButton
ZoneButton
Packages
Packages help organize UML models to increase their
readability
We can use the UML package mechanism to organize
classes into subsystems
Account
Bank
Customer
39
40
Foo
Dada
Amount
Amount
CustomerId
CustomerId
Deposit()
Withdraw()
GetBalance()
Deposit()
Withdraw()
GetBalance()
Account
Amount
CustomerId
Deposit()
Withdraw()
GetBalance()
41
Amount
AccountId
CustomerId
Deposit()
Withdraw()
GetBalance()
Customer
Name
CustomerId
?
Bank
Name
has
Amount
AccountId
Deposit()
Withdraw()
GetBalance()
Customer
owns
Name
CustomerId
43
Bank
Name
Amount
AccountId
Customer
Has
Name
Deposit()
Withdraw()
GetBalance()
Savings
Account
Withdraw()
CustomerId()
Checking
Account
Mortgage
Account
Withdraw()
Withdraw()
44
Savings
Account
Withdraw()
Amount
AccountId
Show
Taxonomies
Deposit()
Withdraw()
GetBalance()
separately
Checking
Account
Mortgage
Account
Withdraw()
Withdraw()
45
Bank
Name
Amount
AccountId
Customer
Has
Deposit()
Withdraw()
GetBalance()
Savings
Account
Withdraw()
Name
CustomerId()
Checking
Account
Mortgage
Account
Withdraw()
Withdraw()
46
Sequence
Diagrams
Focus on
control flow
Passenger
TicketMachine
selectZone()
insertCoins()
pickupChange()
pickUpTicket()
dashed lines
Messages are represented by
arrows
Activations are represented
by narrow rectangles.
47
Passenger
ZoneButton
selectZone()
TarifSchedule
Display
lookupPrice(selection)
price
Dataflow
displayPrice(price)
ChangeProcessor
* insertChange(coin)
Iteration
Condition
CoinIdentifier
Display
CoinDrop
lookupCoin(coin)
price
displayPrice(owedAmount)
[owedAmount<0]returnChange(owedAmount)
Passenger
ChangeProcessor
Creation of Ticket
createTicket(selection)
Ticket
print()
free()
Destruction of Ticket
Activity Diagrams
Document
Incident
Archive
Incident
52
Allocate
Resources
[fire&highPriority]
[notfire&highPriority]
Notify
FireChief
Notify
PoliceChief
53
Open
Incident
Allocate
Resources
Coordinate
Resources
Synchronization
Archive
Incident
Document
Incident
54
Open
Incident
Coordinate
Resources
Dispatcher
Archive
Incident
FieldOfficer
Document
Incident
55
Inactive
Incident
Handled
Closed
Incident
Documented
Archived
Incident
Archived
Document
Incident
Completion of activity
causes state transition
Archive
Incident
Triggerless
transition
56
UML Summary
UML provides a wide variety of notations for
representing many aspects of software
development
Powerful, but complex
Additional References
Martin Fowler
UML Distilled: A Brief Guide to the Standard Object
Modeling Language, 3rd ed., Addison-Wesley, 2003