�Modeling with UML
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1
Overview: modeling with UML
Next lecture
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
What is modeling?
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3
Example: street map
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
Why model CPS?
Why model CPS?
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Systems, Models and Views
Examples:
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
Systems, Models and Views
Aircraft
Flightsimulator
Scale Model
Blueprints
Electrical
Wiring
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
Models, Views and Systems (UML)
System
Model
View
*
*
Depicted by
Described by
Airplane: System
Blueprints: View
Fuel System: View
Electrical Wiring: View
Scale Model: Model
Flight Simulator: Model
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
Concepts and Phenomena
Phenomenon
Concept
Concept is a 3-tuple:
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
Concepts and phenomena
Members
Name
Clock
Purpose
A device that
measures time.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
Concepts in software: Type and Instance
The following relationships are similar:
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
Abstract Data Types & Classes
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
Application and Solution Domain
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
Object-oriented modeling
Application Domain
Solution Domain
Application Domain Model
System Model
Aircraft
TrafficController
FlightPlan
Airport
MapDisplay
FlightPlanDatabase
SummaryDisplay
TrafficControl
TrafficControl
UML Package
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14
What is UML?
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
UML: First Pass
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
UML First Pass
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
UML first pass: Use case diagrams
WatchUser
WatchRepairPerson
ReadTime
SetTime
ChangeBattery
Actor
Use case
Package
Watch
Use case diagrams represent the functionality of the system
from user’s point of view
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
UML first pass: Class diagrams
1
2
push()�release()
1
1
blinkIdx
blinkSeconds()
blinkMinutes()
blinkHours()
stopBlinking()
referesh()
LCDDisplay
Battery
load
1
2
1
Time
now
1
Watch
Class
Association
Multiplicity
Attribute
Operations
Class diagrams represent the structure of the system
state
PushButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
UML first pass: Sequence diagram
:LCDDisplay
blinkHours()
blinkMinutes()
refresh()
commitNewTime()
:Time
incrementMinutes()
stopBlinking()
:Watch
pressButton1()
pressButton2()
pressButtons1And2()
pressButton1()
:WatchUser
Object
Message
Activation
Sequence diagrams represent the behavior as interactions
Actor
Lifeline
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20
UML first pass: Statechart diagrams for objects with interesting dynamic behavior
State
Initial state
Final state
Transition
Event
Represent behavior as states and transitions
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
Other UML Notations
UML provide other notations that we will be introduced in subsequent lectures, as needed.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22
UML Core Conventions
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23
Use Case Diagrams
Passenger
PurchaseTicket
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24
Actors
Passenger
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25
Use Case
A use case represents a class of functionality provided by the system as an event flow.
A use case consists of:
PurchaseTicket
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26
Use Case Diagram: Example
Name: Purchase ticket
Participating actor: Passenger
Entry condition:
Exit condition:
Event flow:
1. Passenger selects the number of zones to be traveled.
2. Distributor displays the amount due.
3. Passenger inserts money, of at least the amount due.
4. Distributor returns change.
5. Distributor issues ticket.
Anything missing?
Exceptional cases!
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27
The <<extends>> Relationship
Passenger
PurchaseTicket
TimeOut
<<extends>>
NoChange
<<extends>>
OutOfOrder
<<extends>>
Cancel
<<extends>>
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28
The <<includes>> Relationship
Passenger
PurchaseSingleTicket
PurchaseMultiCard
NoChange
<<extends>>
Cancel
<<extends>>
<<includes>>
CollectMoney
<<includes>>
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29
Use Case Diagrams: Summary
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30
Class Diagrams
Enumeration getZones()
Price getPrice(Zone)
TarifSchedule
*
*
Trip
zone:Zone
Price: Price
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31
Classes
zone2price
getZones()
getPrice()
TarifSchedule
Table zone2price
Enumeration getZones()
Price getPrice(Zone)
TarifSchedule
Name
Attributes
Operations
Signature
TarifSchedule
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32
Instances
zone2price = {
{‘1’, .20},�{‘2’, .40},
{‘3’, .60}}
tarif_1974:TarifSchedule
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 33
Actor vs Instances
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34
Associations
Price�Zone
Enumeration getZones()
Price getPrice(Zone)
TarifSchedule
TripLeg
*
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35
1-to-1 and 1-to-many Associations
Country
name:String
City
name:String
Has-capital
Polygon
draw()
Point
x: Integer
y: Integer
One-to-one association
One-to-many association
*
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36
Many-to-Many Associations
StockExchange
Company
tickerSymbol
Lists
*
*
StockExchange
Company
Lists
1
*
tickerSymbol
SX_ID
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37
From Problem Statement To Object Model
Pr
oblem Statement: A stock exchange lists many companies. Each
company is uniquely identified by a ticker symbol
Class Diagram:
StockExchange
Company
tickerSymbol
Lists
*
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38
From Problem Statement to Code
public class StockExchange
{
private Vector m_Company = new Vector();
};
public class Company
{
public int m_tickerSymbol;
private Vector m_StockExchange = new Vector();
};
Pr
oblem Statement
:
A
stock exchange lists many companies.
Each company is identified by a ticker Symbol
Class Diagram:
Java Code
StockExchange
Company
tickerSymbol
Lists
*
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39
Aggregation
TicketMachine
ZoneButton
3
Exhaust system
Muffler
diameter
Tailpipe
diameter
1
0..2
Exhaust system
Muffler
diameter
Tailpipe
diameter
1
0..2
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40
Qualifiers
Directory
File
filename
Without qualification
1
*
With qualification
Directory
File
0…1
1
filename
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41
Inheritance
Button
ZoneButton
CancelButton
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42
Object Modeling in Practice: Class Identification
Foo
Betrag
CustomerId
Deposit()
Withdraw()
GetBalance()
Class Identification: Name of Class, Attributes and Methods
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43
Object Modeling in Practice: �Encourage Brainstorming
Foo
Betrag
CustomerId
Deposit()
Withdraw()
GetBalance()
Account
Betrag
CustomerId
Deposit()
Withdraw()
GetBalance()
Naming is important!
Is Foo the right name?
“Dada”
Betrag
CustomerId
Deposit()
Withdraw()
GetBalance()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44
Object Modeling in Practice ctd
Account
Betrag
Deposit()
Withdraw()
GetBalance()
Customer
Name
CustomerId
1) Find New Objects
CustomerId
AccountId
2) Iterate on Names, Attributes and Methods
Bank
Name
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45
Object Modeling in Practice: A Banking System
Account
Betrag
Deposit()
Withdraw()
GetBalance()
Customer
Name
CustomerId
CustomerId
AccountId
AccountId
Bank
Name
1) Find New Objects
2) Iterate on Names, Attributes and Methods
3) Find Associations between Objects
Has
4) Label the assocations
5) Determine the multiplicity of the assocations
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 46
Practice Object Modeling: Iterate, Categorize!
Customer
Name
CustomerId()
Account
Amount
Deposit()
Withdraw()
GetBalance()
CustomerId
AccountId
AccountId
Bank
Name
Has
*
*
Savings
Account
Withdraw()
Checking
Account
Withdraw()
Mortgage
Account
Withdraw()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 47
Packages
DispatcherInterface
Notification
IncidentManagement
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 48
UML sequence diagrams
selectZone()
pickupChange()
pickUpTicket()
insertCoins()
Passenger
TicketMachine
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 49
Nested messages
selectZone()
Passenger
ZoneButton
TarifSchedule
Display
lookupPrice(selection)
displayPrice(price)
price
Dataflow
…to be continued...
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 50
Iteration & condition
Passenger
ChangeProcessor
insertChange(coin)
CoinIdentifier
Display
CoinDrop
displayPrice(owedAmount)
lookupCoin(coin)
price
[owedAmount<0] returnChange(-owedAmount)
Iteration
Condition
…to be continued...
…continued from previous slide...
*
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 51
Creation and destruction
Passenger
ChangeProcessor
…continued from previous slide...
Ticket
createTicket(selection)
free()
Creation
Destruction
print()
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 52
Sequence Diagram Summary
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 53
State Chart Diagrams
State
Initial state
Final state
Transition
Event
Represent behavior as states and transitions
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 54
Activity Diagrams
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 55
Statechart Diagram vs. Activity Diagram
Active
Inactive
Closed
Archived
Incident-
Handled
Incident-
Documented
Incident-
Archived
Statechart Diagram for Incident (similar to Mealy Automaton)
(State: Attribute or Collection of Attributes of object of type Incident)
Activity Diagram for Incident (similar to Moore
(State: Operation or Collection of Operations)
Triggerless
Transition
Completion of activity
causes state transition
Event causes
State transition
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 56
Activity Diagram: Modeling Decisions
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 57
Activity Diagrams: Modeling Concurrency
Synchronization
Splitting
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 58
Activity Diagrams: Swimlanes
Open
Incident
Allocate
Resources
Coordinate
Resources
Document
Incident
Archive
Incident
Dispatcher
FieldOfficer
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 59
What should be done first? Coding or Modeling?
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 60
UML Summary
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 61
Additional Slides
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 62
Models for Plato’s and Aristotle’s Views of Reality
Plato
Aristotle
Using UML, we can illustrate Platon’s and Aristotle’s viewpoints very easily
and see their differences as well
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 63
Model for Plato’s View of Reality
Plato
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 64
Model Aristotle’s Views of Reality
Aristotle
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 65
Comparison of Plato’s and Aristotle’s Views
Plato
Aristotle
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 66