Professional Documents
Culture Documents
Unified Modeling Language
Unified Modeling Language
Actor
ReadTime
SetTime
WatchUser WatchRepairPerson
Use case
ChangeBattery
5
Class Diagram
Class
Operations
6
UML Core Conventions
• Rectangles are classes or instances
• Ovals are functions or use cases
• Instances are denoted with an underlined
names
– myWatch:SimpleWatch
– Joe:Firefighter
9
UML Core Conventions
• Types are denoted with nonunderlined
names
– SimpleWatch
– Firefighter
• Diagrams are graphs
– Nodes are entities
– Arcs are relationships between entities
10
Use Case Diagram
11
A Use Case Diagram
Passenger
PurchaseTicket
12
Actor
13
An Actor
Passenger
14
Use Case
• A use case represents a class of functionality
provided by the system as an event flow.
• A use case consists of:
– Unique name
– Participating actors
– Entry conditions
– Flow of events
– Exit conditions
– Special requirements
15
A Use Case
PurchaseTicket
16
Use Case Example
Name: Purchase Ticket Event flow:
Participating actor: Passenger 1. Passenger selects the number
Entry condition: of zones to be traveled.
• Passenger standing in front of 2. Distributor displays the
ticket distributor. amount due.
• Passenger has sufficient 3. Passenger inserts money, of at
money to purchase ticket. least the amount due.
4. Distributor returns change.
Exit condition: 5. Distributor issues ticket.
• Passenger has ticket.
17
The <<extend>> Relationship
18
<<extend>> Relationships
Passenger
PurchaseTicket
<<extend>> <<extend>>
<<extend>> <<extend>>
OutOfOrder TimeOut
Cancel NoChange
19
The <<include>> Relationship
20
<<include>> Relationships
Passenger
PurchaseMultiCard
<<include>> PurchaseSingleTicket
<<include>>
CollectMoney
<<extend>>
<<extend>>
NoChange
Cancel
21
Class Diagram
22
A Class Diagram
TariffSchedule Trip
zone:Zone
Enumeration getZones() * price:Price
*
Price getPrice(Zone)
23
Class
• A class represent a concept.
• A class encapsulates state (attributes)
& behavior (operations).
• Each attribute has a type.
• Each operation has a signature.
• The class name is the only mandatory
information.
24
A Class
Name
TariffSchedule TariffSchedule
zone2price Table zone2price
Attributes
getZones() Enumeration getZones()
getPrice() Price getPrice(Zone)
Operations
Signature
25
Instance
26
An Instance
tariff_1974:TarifSchedule
zone2price = {
{‘1’, .20},
{‘2’, .40},
{‘3’, .60}}
27
Actor, Class, & Instance
• Actor:
– An entity outside the system to be modeled,
interacting with the system (“Pilot”)
• Class:
– An abstraction modeling an entity in the problem
domain, inside the system to be modeled (“Cockpit”)
• Object:
– A specific instance of a class (“Joe, the inspector”).
28
Association
29
An Association
TarifSchedule TripLeg
30
Associations
Has-capital
Country City
1 1
name:String name:String
1-to-1 association
Polygon 1 * Point
x:Integer
y:Integer
draw()
1-to-many association
31
Aggregation
32
Aggregations
Exhaust System
1 0..2
Muffler Tailpipe
33
Composition
34
Composition
TicketMachine
3
ZoneButton
35
Generalization
Button
CancelButton ZoneButton
37
From Problem Statement to
Code
Problem Statement
38
From Problem Statement to
Code
Problem Statement:
A stock exchange lists many companies.
Each company is identified by a ticker
symbol
39
From Problem Statement
to Code
Class Diagram
lists
StockExchange * * Company
tickerSymbol
Java Code
public class StockExchange {
public Vector m_Company = new Vector();
};
public class Company {
public int m_tickerSymbol;
public Vector m_StockExchange = new Vector();
};
40
UML Sequence Diagram
• Used during requirements analysis
– To refine use case descriptions
– to find additional objects (“participating objects”)
• Used during system design
– to refine subsystem interfaces
• Classes are represented by columns
• Messages are represented by arrows
• Activations are represented by narrow
rectangles
• Lifelines are represented by dashed lines
41
A UML Sequence Diagram
TicketMachine
Passenger
selectZone()
insertCoins()
pickupChange()
pickUpTicket()
42
UML Sequence Diagram
with Nested Messages
43
A UML Sequence Diagram
with Nested Messages
selectZone()
price
lookupPrice(selection)
displayPrice(price)
Dataflow
…to be continued...
44
Sequence Diagram
Observations
• UML sequence diagram represent
behavior in terms of interactions.
• Complement the class diagrams which
represent structure.
• Useful to find participating objects.
• Time consuming to build but worth the
investment.
45
Activity Diagram
• An activity diagram shows flow control within a system
• An activity diagram is a special case of a state chart
diagram in which states are activities (“functions”)
• Two types of states:
– Action state:
• Cannot be decomposed any further
• Happens “instantaneously” with respect to the level of abstraction
used in the model
– Activity state:
• Can be decomposed further
• The activity is modeled by another activity diagram
46
An Activity Diagram
47
Activity Diagram:
Modeling Decisions
[lowPriority]
Open Allocate
Incident Resources
Notify
Police Chief
48
Activity Diagram:
Modeling Concurrency
49
Activity Diagram:
Modeling Concurrency
Splitting Synchronization
Allocate
Resources
Document
Incident
50
Activity Diagrams: Swimlanes
• Actions may be grouped into swimlanes
• Denote the object or subsystem that
implements the actions.
51
Activity Diagrams: Swimlanes
Dispatcher
Allocate
Resources
FieldOfficer
Document
Incident
52
Summary
• UML provides a wide variety of notations for
representing many aspects of software
development
– Powerful, but complex language
– Can be misused to generate unreadable models
– Can be misunderstood when using too many exotic
features
• We concentrate only on a few notations:
– Functional model: use case diagram
– Object model: class diagram
– Dynamic model: sequence diagrams, statechart and
activity diagrams
53
References
• M. Fowler, UML Distilled, 2nd edition, Addison
Wesley, 2000.
• G. Booch, J. Rumbaugh, and I. Jacobson, The
Unified Modeling Language User Guide,
Addison Wesley, 1999.
• B. Bruegge and A. Dutoit, Object-Oriented
Software Engineering Using UML, Patterns, and
Java, 2nd edition, Prentice Hall, 2004
54