Professional Documents
Culture Documents
Lecture-2
UML
1
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
• Types are denoted with nonunderlined names
• SimpleWatch
• Firefighter
• Diagrams are graphs
• Nodes are entities
• Arcs are relationships between entities
2
UML: Use Case Diagrams
Used during requirements elicitation to
represent external behavior
Passenger
• Actors represent roles, that is, a type
of user of the system
• Use cases represent a sequence of
interaction for a type of functionality
• The use case model is the set of all
use cases. It is a complete description
of the functionality of the system and
its environment
PurchaseTicket
3
Actors
• An actor models an external entity
which communicates with the system:
• User
• External system
• Physical environment
Passenger • An actor has a unique name and an
optional description.
• Examples:
• Passenger: A person in the train
• GPS satellite: Provides the system with
GPS coordinates
4
Use Case
A use case represents a class of functionality
provided by the system as an event flow.
5
Use Case Example
Name: Purchase ticket Event flow:
1. Passenger selects the number of
Participating actor: Passenger zones to be traveled.
2. Distributor displays the amount
due.
Entry condition:
3. Passenger inserts money, of at least
• Passenger standing in front of ticket the amount due.
distributor.
4. Distributor returns change.
• Passenger has sufficient money to
purchase ticket. 5. Distributor issues ticket.
6
The <<extend>> Relationship
• <<extend>> relationships represent
exceptional or seldom invoked cases.
Passenger • The exceptional event flows are factored
out of the main event flow for clarity.
• Use cases representing exceptional flows
can extend more than one use case.
PurchaseTicket • The direction of a <<extend>> relationship
is to the extended use case
<<extend>>
<<extend>>
<<extend>>
Cancel NoChange
7
The <<include>> Relationship
• An <<include>> relationship
represents behavior that is
Passenger factored out of the use case.
• An <<include>> represents
PurchaseMultiCard
behavior that is factored out for
reuse, not because it is an
PurchaseSingleTicket exception.
<<include>> • The direction of a <<include>>
relationship is to the using use
<<include>>
case (unlike <<extend>>
relationships).
CollectMoney
<<extend>> <<extend>>
NoChange Cancel
8
Class Diagrams
TariffSchedule Trip
zone:Zone
Enumeration getZones() price:Price
* *
Price getPrice(Zone)
9
Classes
TariffSchedule
Table zone2price
Enumeration getZones()
Name Price getPrice(Zone)
TariffSchedule Signature
zone2price Attributes
getZones()
getPrice()
Operations
tariff_1974:TarifSchedule
zone2price = {
{‘1’, .20},
{‘2’, .40},
{‘3’, .60}}
12
Associations
TarifSchedule TripLeg
1-to-1 association
Polygon 1 * Point
x:Integer
y:Integer
draw()
1-to-many association
14
Aggregation
• An aggregation is a special case of association denoting a
“consists of” hierarchy.
• The aggregate is the parent class, the components are the
children class.
Exhaust System
1 0..2
Muffler Tailpipe
Composition
• A solid diamond denote composition, a strong form of
aggregation where components cannot exist without the
aggregate.
TicketMachine
3
ZoneButton
Generalization
Button
CancelButton ZoneButton
17
From Problem Statement to Code
Problem Statement
A stock exchange lists many companies. Each company is identified by a ticker symbol
Class Diagram
lists
StockExchange * * Company
tickerSymbol
Java Code
18
UML Sequence Diagrams
• Used during requirements analysis
TicketMachine • To refine use case descriptions
Passenger • To find additional objects
selectZone() (“participating objects”)
• Used during system design
• to refine subsystem interfaces
• Classes are represented by columns
insertCoins()
• Messages are represented by arrows
• Activations are represented by narrow
rectangles
pickupChange()
• Lifelines are represented by dashed
lines
pickUpTicket()
19
UML Sequence Diagrams: Nested Messages
selectZone()
lookupPrice(selection)
price
displayPrice(price)
Dataflow
…to be continued...
21
Activity Diagrams
• An activity diagram shows flow control within a system
22
Activity Diagram: Modeling Decisions
[lowPriority]
Open Allocate
Incident Resources
[fire & highPriority]
Notify
Police Chief
23
Activity Diagrams: Modeling Concurrency
• Synchronization of multiple activities
• Splitting the flow of control into multiple threads
Splitting Synchronization
Allocate
Resources
Document
Incident
24
Activity Diagrams: Swimlanes
• Actions may be grouped into swimlanes to denote
the object or subsystem that implements the actions.
Dispatcher
Allocate
Resources
FieldOfficer
Document
Incident
25
Similarities Between Sequence and Activity Diagram:
•Both Sequence Diagram and Activity Diagram are UML diagrams.
•Both Sequence and Activity Diagrams are used to represent the control flow of
messages.
The Sequence diagram shows the message flow from one The Activity diagram shows the message flow from one
object to another object. activity to another.
Sequence diagram is used for the purpose of dynamic Activity diagram is used for the purpose of functional
modelling. modelling.
Sequence diagram is mainly used to represent the time order Activity diagram is used to represent the execution of the
of a process. process.
26
Group Assignment (30%)
Form a group 3 members, then identify scenario/problem and then
do the following:
1. Give appropriate title for the identified problem
2. Write background information and show the gap that the
proposed system will address.
3. Draw the following three UML Diagrams:
1. Use Case diagram
2. Class diagram
3. Sequence diagram
28