UML Diagrams With examples-NT
UML Diagrams With examples-NT
DIAGRAMS
Modeling with UML
Overview: modeling with UML
• What is modeling?
• What is UML?
• Use case diagrams
• Class diagrams
Next step:
• Sequence diagrams
• Activity diagrams
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
Application and Solution Domain
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
We use Models to describe Software
Systems
• System model: Object model + functional
model + dynamic model
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Overview of UML Diagrams
Behavioral
Structural
: behavioral features of a system / business
process
: element of spec. irrespective of time
• Activity
• State machine
• Class
• Use case
• Component
• Interaction
• Deployment
• Object
• Composite structure
Interaction
: emphasize object interaction
• Package
• Communication(collabe
ration)
• Sequence
• Interaction overview
• Timing
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
Another view on UML Diagrams
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
Outline of the Diagrams
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://www.booch.
http://www.ivarjacobson.com com/
UML
• Generic standard for modeling systems
• Current Version: UML 2.5.1
• Information at the OMG portal http://www.uml.org/
• Commercial tools:
• Rational (IBM),Together (Borland), Visual Architect (Visual
Paradigm), Enterprise Architect (Sparx Systems)
• Open Source tools http://www.sourceforge.net/
• ArgoUML, StarUML, Umbrello (for KDE), PoseidonUML
• Example of research tools: Unicase, Sysiphus
• Based on a unified project model for modeling,
collaboration and project organization
• http://unicase.org
• http://sysiphus.in.tum.de/
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
UML: First Pass
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
STATIC UML MODELS
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
UML
USE CASE DIAGRAM
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
UML Use Case Diagrams
Used during requirements elicitation
and analysis to represent external
behavior (“visible from the outside of
the system”)
An Actor represents a role, that
is, a type of user of the system
Passenger
A use case represents a class of
functionality provided by the system
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
Use cases diagram
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
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)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20
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
PurchaseTicket • 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
6. Special requirements.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
Textual Use Case
Description Example PurchaseTicket
Passenger
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22
Review of Use Case Diagrams:
3 Important Terms
Used during requirements elicitation and
analysis to represent behavior visible from
the outside of the system
An actor represents a role, that
is, a type of user of the system
Student A use case represents a class of
functionality provided by the system
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23
Actor
• An actor is a model for an external
entity which interacts with the
system:
• EndUser, Administrator
• External system (Another system)
• Physical environment (e.g. Weather)
• An actor has a unique name and an
optional description
Student Optional
• Examples: Description
• Student: A studying person
• Teaching Assistant: Member of
teaching staff who supports the
Name instructor.
• Random Number generator
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24
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
DoHomework • 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
6. Special requirements.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25
Textual Use Case
Description Example Student
Actor.
System boundary
• 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 28
The <<extends>> Relationship
• <<extends>> relationships
model exceptional or seldom
invoked cases
• The exceptional event flows
Passenger are separated from the main
event flow for clarity
• The direction of an
<<extends>> relationship is
PurchaseTicket towards 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 29
The <<includes>> Relationship
• <<includes>> relationship
represents common
functionality needed in more
than one use case
Passenger
• <<includes>> behavior is
separated for reuse, not
PurchaseMultiCard because it is an exception
PurchaseSingleTicket
• The direction of a
<<includes>> relationship is
<<includes>>
to the using use case (unlike
<<includes>> the direction of the
<<extends>> relationship).
CollectMoney
<<extends>> <<extends>>
<<extends>>
DrinkCoffee Sleep
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31
The <<include>> Relationship
• <<include>> relationship
represents common
DoHomework functionality needed in more
than one use case
Student
• <<include>> behavior is
factored out for reuse, not
HoldExercise because it is an exception
GiveLecture • The direction of a
<<include>> relationship is
<<include>>
to the using use case (unlike
<<include>> the direction of the
<<extend>> relationship).
AskQuestion
<<extend>> <<extend>>
<<extend>>
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 33
Use cases diagram
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39
Use Case Diagrams: Summary -short
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40
UML
COMPONENT DIAGRAM
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41
Component Diagram
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 46
UML
CLASS DIAGRAM
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 47
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 48
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 49
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 50
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 51
Class Diagrams
TarifSchedule Trip
Table zone2price
zone:Zone
Enumeration getZones()
Price getPrice(Zone)
* * Price: Price
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 52
Classes Type
TarifSchedule
Table zone2price
Enumeration getZones()
Name Price getPrice(Zone)
TarifSchedule
zone2price Attributes Signature
getZones()
getPrice()
Operations TarifSchedule
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 54
Actor vs Class vs Object
• 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 (instance)
• 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 55
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 56
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 57
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 58
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 59
Associations
TarifSchedule TripLeg
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 60
1-to-1 and 1-to-many Associations
Country 1 1 City
name:String name:String
1-to-1 association
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 61
Many-to-Many Associations
Company
StockExchange * * tickerSymbol
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 62
From Problem Statement To Object Model
Class Diagram:
StockExchange * * Company
Lists
tickerSymbol
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 63
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 64
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 65
Part-of Hierarchy (Aggregation)
Computer
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 66
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 67
Qualification: Another Example
Company
StockExchange * Lists
* tickerSymbol
StockExchange
*
tickerSymbol
Lists
*
1 Company
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 68
Inheritance
Button
CancelButton ZoneButton
Account
Bank Customer
Foo
Amount
CustomerId
Deposit()
Withdraw()
GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 71
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 72
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 73
Object Modeling in Practice: Associations
Account
? * Amount
AccountId * Customer
Bank has CustomerId
AccountId owns
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 75
Practice Object Modeling: Simplify,
Organize
Account
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 76
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 77
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 78
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 79
DYNAMIC UML MODELS
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 80
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 81
UML
SEQUENCE DIAGRAM
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 82
Sequence diagram: Basic Notation
Lifeline
Execution
Specification
Message
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 84
Messages
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 85
Message Types
• Asynchronous
• Synchronous
• Call and Object creation
• Reply
• Lost
• Found
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 86
Sequence Diagrams Focus on
Controlflow
selectZone()
lookupPrice(selection)
price
displayPrice(price)
Dataflow
…continued on next slide...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 88
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 89
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 91
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 92
UML
ACTIVITY DIAGRAM
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 93
Activity Diagrams
• An activity diagram is a special case of a state
chart diagram
• The states are activities (“functions”)
• An activity diagram is useful to depict the
workflow in a system
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 94
Activity Diagrams allow to model Decisions
Decision
[lowPriority]
Open Allocate
Incident Resources
Notify
Fire Chief
Notify
Police Chief
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 95
Activity Diagrams can model Concurrency
Allocate
Splitting Resources Synchronization
Document
Incident
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 96
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 97
Activity Diagram vs. Statechart Diagram
Statechart Diagram for Incident
Focus on the set of attributes of a single abstraction (object, system)
Event causes
state transition
Triggerless
Completion of activity transition
causes state transition
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 98
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 99
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 100
UML
STATE CHART DIAGRAM
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 101
UML Statechart diagram
Event Initial state
button1&2Pressed button2Pressed
Blink Increment
Hours Hours
Transition button1Pressed
button1&2Pressed button2Pressed
Blink Increment
Minutes Minutes
State
button1Pressed
button2Pressed
Stop Blink Increment
Blinking Seconds Seconds
Final state
Represents behavior of a single object with interesting
dynamic behavior.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 102
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 103
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 104
UML Summary
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 105
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 106