L3 ModelingWithUML Ch02lect2
L3 ModelingWithUML Ch02lect2
• What is UML?
• A more detailed view on
Use case diagrams
Class diagrams
Sequence diagrams
Activity diagrams
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
2
What is UML? Unified Modeling Language
• Convergence of different notations used in object-
oriented methods, mainly
• OMT (James Rumbaugh and collegues), OOSE (Ivar
Jacobson), Booch (Grady Booch)
• They also developed the Rational Unified Process,
which became the Unified Process in 1999
Developed the
Booch method
25 year at GE Research, At Ericsson until 1994, (“clouds”), ACM
where he developed OMT, developed use cases and the Fellow 1995, and
joined (IBM) Rational in CASE tool Objectory, at IBM IBM Fellow 2003
1994, CASE tool OMTool Rational since 1995, http://
http://www.ivarjacobson.com www.booch.com/
UML Basic Notation: First Summary
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
4
UML First Pass (covered in Last Lecture)
• Use case diagrams
• Describe the functional behavior of the system as seen
by the user
• Class diagrams
• Describe the static structure of the system: Objects,
attributes, associations
• Sequence diagrams
• Describe the dynamic behavior between objects of the
system
• Statechart diagrams
• Describe the dynamic behavior of an individual object
• Activity diagrams
• Describe the dynamic behavior of a system, in particular
the workflow.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
5
UML Use Case Diagrams
Used during requirements elicitation and
TicketSystem
analysis to represent external behavior
(“visible from the outside of the system”)
An Actor represents a role, that is, a
Passenger type of user of the system
A use case represents a class of
functionality provided by the system
Use case model:
The set of all use cases that
completely describe the functionality
of the system.
PurchaseTicket
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
7
Use Case
• A use case represents a class 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:
PurchaseTicket
1. Unique name
2. Participating actors
3. Entry conditions
4. Exit conditions
5. Flow of events
6. Special requirements.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
8
Textual Use Case
Description Example PurchaseTicket
Passenger
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
9
Uses Cases can be related
• Extends Relationship
• To represent seldom invoked use cases or exceptional
functionality
• Includes Relationship
• To represent functional behavior common to more than
one use case.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
10
The <<extends>> Relationship
• <<extends>> relationships
model exceptional or seldom
invoked cases
• The exceptional event flows
Passenger are factored out of the main
event flow for clarity
• The direction of an
<<extends>> relationship is to
PurchaseTicket the extended use case
• Use cases representing
<<extends>> exceptional flows can extend
more than one use case.
<<extends>>
<<extends>>
OutOfOrder <<extends>> TimeOut
Cancel NoChange
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
11
The <<includes>> Relationship
• <<includes>> relationship
represents common
functionality needed in more
than one use case
Passenger
• <<includes>> behavior is
factored out for reuse, not
PurchaseMultiCard because it is an exception
• The direction of a
PurchaseSingleTicket
<<includes>> relationship is
<<includes>>
to the using use case (unlike
<<includes>> the direction of the
<<extends>> relationship).
CollectMoney
<<extends>>
<<extends>>
NoChange Cancel
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
12
Use Case Models can be packaged
Classifier (System Boundary)
Use Case
Actor.
System boundary
TarifSchedule Trip
Table zone2price
zone:Zone
Enumeration getZones()
* * Price: Price
Price getPrice(Zone)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
15
Classes Type
TarifSchedule
Table zone2price
Enumeration getZones()
Name Price getPrice(Zone)
TarifSchedule
zone2price Attributes Signature
getZones()
getPrice()
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”).
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
17
Instances
tarif2006:TarifSchedule :TarifSchedule
zone2price = { zone2price = {
{‘1’, 0.20}, {‘1’, 0.20},
{‘2’, 0.40}, {‘2’, 0.40},
{‘3’, 0.60}} {‘3’, 0.60}}
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
18
Associations
TarifSchedule TripLeg
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
19
1-to-1 and 1-to-many Associations
Country 1 1 City
name:String name:String
1-to-1 association
3..* Point
Polygon
x: Integer
y: Integer
draw()
1-to-many association
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
20
Many-to-many Associations
StockExchange * * Company
Lists tickerSymbol
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
21
Examples of Multiplicity
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
22
From a Simple Problem Statement To Class
Model
Problem Statement: A stock exchange lists many companies.
Each company is uniquely identified by a ticker symbol
Class Diagram:
StockExchange * * Company
Lists
tickerSymbol
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
23
From Scenario To Class Diagram
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
24
Class Diagram for Warehouse on Fire Scenario
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
25
From Problem Statement to Code
Problem Statement : A stock exchange lists many companies.
Each company is identified by a ticker symbol
Class Diagram:
StockExchange * * Company
Lists tickerSymbol
Java Code
public class StockExchange
{
private Vector m_Company = new Vector();
Associations
};
are mapped to
public class Company
{ Attributes!
public int m_tickerSymbol;
private Vector m_StockExchange = new Vector();
};
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
26
Qualifiers
Without qualification
1 * File
Directory
filename
With qualification
1 0..1
Directory filename File
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
27
Aggregation
• An aggregation is a special case of association denoting
a “consists-of” hierarchy
Exhaust system
• The aggregate is the parent class,
the components are the children classes
1 0..2
Muffler Tailpipe
diameter diameter
3
ZoneButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
28
Aggregation Examles
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
29
Aggregation vs Association
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
30
Inheritance
Button
CancelButton ZoneButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
32
Packages
• Packages help you to organize UML models to
increase their readability
• We can use the UML package mechanism to organize
classes into subsystems
Account
Bank Customer
• Any complex system can be decomposed into
subsystems, where each subsystem is modeled as a
package.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
33
Object Modeling in Practice
Foo
Amount
CustomerId
Deposit()
Withdraw()
GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
34
Object Modeling in Practice: Brainstorming
“Dada” Foo
Amount Amount
CustomerId CustomerId
Deposit() Deposit()
Withdraw() Withdraw()
GetBalance() GetBalance()
Account
Amount
CustomerId
Deposit()
Withdraw()
Is Foo the right name? GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
35
Object Modeling in Practice: More classes
Account
Amount Customer
Bank AccountId
CustomerId
Name
Name Deposit() CustomerId
Withdraw()
GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
36
Object Modeling in Practice: Associations
Account
? * Amount
AccountId * owns
Customer
Bank has CustomerId
AccountId
Name
Deposit() 2
Name CustomerId
Withdraw()
GetBalance()
Name
* Amount
* Has Name
AccountId
CustomerId
AccountId
Deposit()
Withdraw()
GetBalance() CustomerId()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
38
Practice Object Modeling: Simplify, Organize
Account
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
39
Practice Object Modeling: Simplify, Organize
Account
Bank Customer
Name
* Amount
* Has Name
AccountId
CustomerId
AccountId
Deposit()
Withdraw()
GetBalance() CustomerId()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
40
Sequence Diagrams Focus on
Controlflow
selectZone()
lookupPrice(selection)
price
displayPrice(price)
Dataflow
…continued on next slide...
• The source of an arrow indicates the activation which sent
the message
• Horizontal dashed arrows indicate data flow, for example
return results from a message
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
42
Sequence Diagrams: Iteration & Condition
…continued from previous slide...
*insertChange(coin) lookupCoin(coin)
price
Iteration displayPrice(owedAmount)
[owedAmount<0] returnChange(-owedAmount)
Condition
…continued on next slide...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
43
Creation and destruction
…continued from previous slide...
ChangeProcessor
Passenger Creation of Ticket
createTicket(selection)
Ticket
print()
free()
Destruction of Ticket
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
44
Sequence Diagram Properties
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
45
Outline of this Class
• What is UML?
• A more detailed view on
Use case diagrams
Class diagrams
Sequence diagrams
Activity diagrams
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
46
UML 2 Activity Diagrams
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
47
Example: Simple Acitivity Diagram for Incident
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
48
Example: Open Incident – Control Nodes
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
49
Example: Open Incident – Fork & Join
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
50
Activity Diagrams: Grouping of Activities
Allocate Dispatcher
Resources
FieldOfficer
Document
Incident
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
51
Control Nodes in an Activity Diagram
• Initial node
• Final node
• Activity final node
• Flow final node
• Fork node
• Join node
• Merge node
• Decision node
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
52
Activity Diagram Example
Fork Join Merge
node node node
Initial
node
Final
node
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
53
Example of a Activity Diagram with a Frame
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
54
The Activity Diagram without Frame
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
55
Activity Diagram: Activity Nodes & Edges
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
56
Action Nodes and Object Nodes
• Action Node
Action
Name
• Object Node
Object
Name
Write Review
Thesis Thesis Thesis
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
57
Activity Diagram Example
Action
Object
node
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
58
Activity Diagram Example
Control
flow
Object
flow
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
59
Summary: Activity Diagram Example
Fork Join Merge
node node node
Initial
node
Control
flow Final
node
Action
Object
node Object
flow
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
60
State Chart Diagrams vs Activity Diagrams
• An activity diagram that contains only activities
can be seen as a special case of a state chart
diagram
• Such an activity diagram is useful to describe the
overall workflow of a system
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
61
Statechart Diagram vs Activity Diagram
Statechart Diagram for Incident
Focus on the set of attributes of a single abstraction (object,
system) Event causes
state transition
Completion of activity
causes state transition Triggerless
transition
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
62
UML Summary
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
63
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java
64