Uml Ooad
Uml Ooad
What is modeling?
What is UML?
Use case diagrams
Class diagrams
Next lecture
Sequence diagrams
Activity diagrams
Knight Object-Oriented
What is modeling?
Knight Object-Oriented
Example: street map
Knight Object-Oriented
Why model software?
Knight Object-Oriented
Systems, Models and Views
Examples:
System: Aircraft
Models: Flight simulator, scale model
Views: All blueprints, electrical wiring, fuel system
Knight Object-Oriented
Systems, Models and Views
Flightsimulator
Blueprints
Aircraft
Model 2
View 2
View 1
System
View 3
Model 1
Electrical
Wiring
Scale Model
Knight Object-Oriented
Models, Views and Systems (UML)
* *
System Model View
Described by Depicted by
Airplane: System
Knight Object-Oriented
Concepts and Phenomena
Phenomenon
An object in the world of a domain as you perceive it
Example: The lecture you are attending
Example: My black watch
Concept
Describes the properties of phenomena that are common.
Example: Lectures on software engineering
Example: Black watches
Concept is a 3-tuple:
Name (To distinguish it from other concepts)
Purpose (Properties that determine if a phenomenon is a member
of a concept)
Members (The set of phenomena which are part of the concept)
Knight Object-Oriented
Concepts and phenomena
Abstraction
Classification of phenomena into concepts
Modeling
Development of abstractions to answer specific questions about a set of
phenomena while ignoring irrelevant details.
Knight Object-Oriented
Concepts in software: Type and Instance
Type:
An abstraction in the context of programming languages
Name: int, Purpose: integral number, Members: 0, -1, 1, 2, -2, . . .
Instance:
Member of a specific type
The type of a variable represents all possible instances the
variable can take
Knight Object-Oriented
Abstract Data Types & Classes
Abstract data type
Special type whose implementation is hidden Watch
from the rest of the system.
time
Class: date
An abstraction in the context of object-
SetDate(d)
oriented languages
Like an abstract data type, a class
encapsulates both state (variables) and
behavior (methods)
Class Vector CalculatorWatch
Knight Object-Oriented
Application and Solution Domain
Knight Object-Oriented
Object-oriented modeling
TrafficController FlightPlanDatabase
Aircraft
Knight Object-Oriented
What is UML?
Knight Object-Oriented
UML: First Pass
Knight Object-Oriented
UML First Pass
Knight Object-Oriented
UML first pass: Use case diagrams
Actor
ReadTime
SetTime
WatchUser WatchRepairPerson
ChangeBattery
Association
Class
Multiplicity Watch
1 1 1 1
2 1 2 1
PushButton LCDDisplay Battery Time
state blinkIdx load now
push() blinkSeconds()
release() blinkMinutes()
blinkHours()
stopBlinking()
referesh()
Attribute
Operations
Knight Object-Oriented
UML first pass: Sequence diagram
Actor Object
pressButton1() blinkHours()
pressButton1() blinkMinutes()
Activation Lifeline
[button1Pressed]
Transition
[button1&2Pressed] [button2Pressed]
BlinkMinutes IncrementMin.
[button1Pressed]
[button1&2Pressed] [button2Pressed]
BlinkSeconds IncrementSec.
Implementation diagrams
Component diagrams
Deployment diagrams
Introduced in lecture on System Design
Object constraint language
Introduced in lecture on Object Design
Knight Object-Oriented
UML Core Conventions
Knight Object-Oriented
Use Case Diagrams
Knight Object-Oriented
Actors
Knight Object-Oriented
Use Case
Knight Object-Oriented
Use Case Diagram: Example
Exit condition:
Anything missing?
Passenger has ticket.
Exceptional cases!
Knight Object-Oriented
The <<extends>> Relationship
<<extends>> relationships
represent exceptional or seldom
invoked cases.
The exceptional event flows are
Passenger factored out of the main event
flow for clarity.
Use cases representing exceptional
flows can extend more than one
PurchaseTicket use case.
The direction of a <<extends>>
<<extends>> relationship is to the extended use
case
<<extends>>
<<extends>>
Cancel NoChange
Knight Object-Oriented
The <<includes>> Relationship
<<includes>> relationship
represents behavior that is factored
Passenger
out of the use case.
<<includes>> behavior is factored
out for reuse, not because it is an
PurchaseMultiCard exception.
PurchaseSingleTicket The direction of a <<includes>>
<<includes>>
relationship is to the using use
case (unlike <<extends>>
<<includes>> relationships).
CollectMoney
<<extends>> <<extends>>
NoChange Cancel
Knight Object-Oriented
Use Case Diagrams: Summary
Knight Object-Oriented
Class Diagrams
TarifSchedule
Trip
Enumeration getZones() zone:Zone
* * Price: Price
Price getPrice(Zone)
Knight Object-Oriented
Classes
TarifSchedule
Table zone2price
Enumeration getZones()
Name Price getPrice(Zone)
TarifSchedule
zone2price Attributes Signature
getZones()
getPrice()
Operations TarifSchedule
Knight Object-Oriented
Instances
tarif_1974:TarifSchedule
zone2price = {
{‘1’, .20},
{‘2’, .40},
{‘3’, .60}}
Knight Object-Oriented
Actor vs Instances
Knight Object-Oriented
Associations
TarifSchedule TripLeg
Knight Object-Oriented
1-to-1 and 1-to-many Associations
One-to-one association
Point
Polygon
* x: Integer
y: Integer
draw()
One-to-many association
Knight Object-Oriented
Many-to-Many Associations
Lists
StockExchange * * Company
tickerSymbol
StockExchange *
tickerSymbol
Lists 1
SX_ID
Company
Knight Object-Oriented
From Problem Statement To Object Model
Class Diagram:
StockExchange * * Company
Lists
tickerSymbol
Knight Object-Oriented
From Problem Statement to Code
Class Diagram:
StockExchange * * Company
Lists tickerSymbol
Java Code
public class StockExchange
{
private Vector m_Company = new Vector();
};
public class Company
{
public int m_tickerSymbol;
private Vector m_StockExchange = new Vector();
};
Knight Object-Oriented
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 Exhaust system
1 0..2 1 0..2
Muffler Tailpipe Muffler Tailpipe
3
ZoneButton
Knight Object-Oriented
Qualifiers
Without qualification
1 * File
Directory
filename
With qualification
1 0…1
Directory filename File
Knight Object-Oriented
Inheritance
Button
CancelButton ZoneButton
Knight Object-Oriented
Object Modeling in Practice: Class Identification
Foo
Betrag
CustomerId
Deposit()
Withdraw()
GetBalance()
Knight Object-Oriented
Object Modeling in Practice:
Encourage Brainstorming
“Dada” Foo
Betrag Betrag
CustomerId CustomerId
Deposit() Deposit()
Withdraw() Withdraw()
GetBalance() GetBalance()
Account
Betrag
CustomerId
Deposit()
Naming is important! Withdraw()
Is Foo the right name? GetBalance()
Knight Object-Oriented
Object Modeling in Practice ctd
Account
Betrag Customer
Bank AccountId
CustomerId
Name
Name Deposit() CustomerId
Withdraw()
GetBalance()
Knight Object-Oriented
Object Modeling in Practice: A Banking System
Account
Betrag
Bank AccountId
CustomerId
AccountId
* Has
Customer
Name
Name Deposit() CustomerId
Withdraw()
GetBalance()
Name
* Amount
* Has Name
AccountId
CustomerId
AccountId
Deposit()
Withdraw()
GetBalance() CustomerId()
Knight Object-Oriented
Packages
A package is a UML mechanism for organizing elements into
groups (usually not an application domain concept)
Packages are the basic grouping construct with which you may
organize UML models to increase their readability.
DispatcherInterface
Notification IncidentManagement
Knight Object-Oriented
UML sequence diagrams
Knight Object-Oriented
Nested messages
selectZone()
lookupPrice(selection)
price
displayPrice(price)
Dataflow
…to be continued...
The source of an arrow indicates the activation which sent the message
An activation is as long as all nested activations
Horizontal dashed arrows indicate data flow
Vertical dashed lines indicate lifelines
Knight Object-Oriented
Iteration & condition
…continued from previous slide...
* insertChange(coin)
lookupCoin(coin)
price
Iteration displayPrice(owedAmount)
[owedAmount<0] returnChange(-owedAmount)
Condition
…to be continued...
Knight Object-Oriented
Creation and destruction
…continued from previous slide...
ChangeProcessor
Passenger
Creation
createTicket(selection)
Ticket
print()
free()
Destruction
Knight Object-Oriented
Sequence Diagram Summary
Knight Object-Oriented
State Chart Diagrams
Event Initial state State
[button1&2Pressed] [button2Pressed]
BlinkHours IncrementHrs
Transition
[button1Pressed]
[button1&2Pressed] [button2Pressed]
BlinkMinutes IncrementMin.
[button1Pressed]
[button1&2Pressed] [button2Pressed]
BlinkSeconds IncrementSec.
StopBlinking
Final state
Knight Object-Oriented
Statechart Diagram vs. Activity Diagram
atechart Diagram for Incident (similar to Mealy Automaton)
tate: Attribute or Collection of Attributes of object of type Incident
Event causes
State transition
Triggerless
Completion of activity Transition
causes state transition
Knight Object-Oriented
Activity Diagram: Modeling Decisions
[lowPriority]
Open Allocate
Incident Resources
Notify
Police Chief
Knight Object-Oriented
Activity Diagrams: Modeling Concurrency
Allocate
Splitting Resources Synchronization
Document
Incident
Knight Object-Oriented
Activity Diagrams: Swimlanes
Allocate Dispatcher
Resources
FieldOfficer
Document
Incident
Knight Object-Oriented
What should be done first? Coding or Modeling?
It all depends….
Forward Engineering:
Creation of code from a model
Greenfield projects
Reverse Engineering:
Creation of a model from code
Interface or reengineering projects
Roundtrip Engineering:
Move constantly between forward and reverse engineering
Useful when requirements, technology and schedule are changing
frequently
Knight Object-Oriented
UML Summary
Knight Object-Oriented