Professional Documents
Culture Documents
ObjectOrientedSoftwareEngineering
Chapter2,
ModelingwithUML
Overview:modelingwithUML
Whatismodeling?
WhatisUML?
Usecasediagrams
Classdiagrams
Sequencediagrams
Activitydiagrams
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
Whatismodeling?
Modelingconsistsofbuildinganabstractionofreality.
Abstractionsaresimplificationsbecause:
Theyignoreirrelevantdetailsand
Theyonlyrepresenttherelevantdetails.
Whatisrelevantorirrelevantdependsonthepurposeofthe
model.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
Example:streetmap
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
Whymodelsoftware?
Whymodelsoftware?
Softwareisgettingincreasinglymorecomplex
WindowsXP>40millionlinesofcode
Asingleprogrammercannotmanagethisamountofcodeinits
entirety.
Codeisnoteasilyunderstandablebydeveloperswhodidnot
writeit
Weneedsimplerrepresentationsforcomplexsystems
Modelingisameansfordealingwithcomplexity
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
ApplicationandSolutionDomain
ApplicationDomain(RequirementsAnalysis):
Theenvironmentinwhichthesystemisoperating
SolutionDomain(SystemDesign,ObjectDesign):
Theavailabletechnologiestobuildthesystem
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
ObjectorientedModeling
Application Domain
(Phenomena)
Solution Domain
(Phenomena)
TrafficControl
UML
Package
Aircraft TrafficController
Airport
BerndBruegge&AllenH.Dutoit
FlightPlan
MapDisplay
Summary
Display
FlightPlanDatabase
TrafficControl
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
WhatisUML?
UML(UnifiedModelingLanguage)
Nonproprietarystandardformodelingsoftwaresystems,OMG
Convergenceofnotationsusedinobjectorientedmethods
OMT(JamesRumbaughandcollegues)
Booch(GradyBooch)
OOSE(IvarJacobson)
CurrentVersion:UML2.2
InformationattheOMGportalhttp://www.uml.org/
Commercialtools:Rational(IBM),Together(Borland),VisualArchitect
(businessprocesses,BCD)
OpenSourcetools:ArgoUML,StarUML,Umbrello
CommercialandOpensource:PoseidonUML(Gentleware)
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
UML:FirstPass
Youcanmodel80%ofmostproblemsbyusingabout20%
UML
Weteachyouthose20%
8020rule:Paretoprinciple
(http://en.wikipedia.org/wiki/Pareto_principle)
80%ofyourprofitscomefrom20%ofyourcustomers
80%ofyourcomplaintscomefrom20%ofyourcustomers
80%ofyourprofitscomefrom20%ofthetimeyouspend
80%ofyoursalescomefrom20%ofyourproducts
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
UMLFirstPass
Usecasediagrams
Describethefunctionalbehaviorofthesystemasseenbythe
user
Classdiagrams
Describethestaticstructureofthesystem:Objects,attributes,
associations
Sequencediagrams
Describethedynamicbehaviorbetweenobjectsofthesystem
Statediagrams
Describethedynamicbehaviorofanindividualobject
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
10
UMLCoreConventions
AllUMLDiagramsdenotegraphsofnodesandedges
Nodesareentitiesanddrawnasrectanglesorovals
Rectanglesdenoteclassesorinstances
Ovalsdenotefunctions
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
11
UMLfirstpass:Usecasediagrams
Classifier
Use Case
Actor
System boundary
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
12
UMLfirstpass:Classdiagrams
Association
Multiplicity
2
PushButton
Class
SimpleWatch
1
1
Display
1
2
Battery
1
Time
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
13
UMLfirstpass:Classdiagrams
Class diagrams represent the structure of the system
Association
Class
Multiplicity
1
2
PushButton
state
push()
release()
Attribute
Watch
1 1 1
2
1
LCDDisplay
blinkIdx
blinkSeconds()
blinkMinutes()
blinkHours()
stopBlinking()
referesh()
BerndBruegge&AllenH.Dutoit
Battery
Load
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
1
Time
Now
Operations
14
UMLfirstpass:Sequencediagram
Actor
Message
:WatchUser
Object
:Watch
pressButton1()
pressButton1()
pressButton2()
Lifeline
:LCDDisplay
:Time
blinkHours()
blinkMinutes()
incrementMinutes()
refresh()
pressButton1and2()
commitNewTime()
Activation
stopBlinking()
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
15
UMLfirstpass:Statechartdiagrams
Initial state
Event
button1&2Pressed
Blink
Hours
Transition
button1&2Pressed
State
button2Pressed
Increment
Hours
button1Pressed
Blink
Minutes
button2Pressed
Increment
Minutes
button1Pressed
Stop
Blinking
Blink
Seconds
button2Pressed
Increment
Seconds
Final state
Represent behavior of a single object with interesting
dynamic behavior.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
16
OtherUMLNotations
UMLprovidesmanyothernotations,forexample
Deploymentdiagramsformodelingconfigurations
Usefulfortestingandforreleasemanagement
Weintroducetheseandothernotationsaswegoalonginthe
lectures
OCL:AlanguageforconstrainingUMLmodels
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
17
Whatshouldbedonefirst?CodingorModeling?
Italldepends.
ForwardEngineering
Creationofcodefromamodel
Startwithmodeling
Greenfieldprojects
ReverseEngineering
Creationofamodelfromexistingcode
Interfaceorreengineeringprojects
RoundtripEngineering
Moveconstantlybetweenforwardandreverseengineering
Reengineeringprojects
Usefulwhenrequirements,technologyandschedulearechanging
frequently.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
18
UMLSecondPass
Usecasediagrams
Describethefunctionalbehaviorofthesystemasseenbytheuser
Classdiagrams
Describethestaticstructureofthesystem:Objects,attributes,
associations
Sequencediagrams
Describethedynamicbehaviorbetweenobjectsofthesystem
Statediagrams
Describethedynamicbehaviorofanindividualobject
Activitydiagrams
Describethedynamicbehaviorofasystem,inparticularthe
workflow.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
19
UMLUseCaseDiagrams
Used during requirements elicitation
and analysis to represent external
behavior (visible from the outside of
the system)
AnActorrepresentsarole,thatis,atype
ofuserofthesystem
Passenger
PurchaseTicket
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
20
Actors
Anactorisamodelforanexternalentity
whichinteracts(communicates)withthe
system:
User
Externalsystem(Anothersystem)
Physicalenvironment(e.g.Weather)
Passenger
Name
BerndBruegge&AllenH.Dutoit
Anactorhasauniquenameandanoptional
description
Optional
Examples:
Description
Passenger:Apersoninthetrain
GPSsatellite:Anexternalsystemthatprovides
thesystemwithGPScoordinates.
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
21
UseCase
PurchaseTicket
BerndBruegge&AllenH.Dutoit
Ausecaserepresentsaclassof
functionalityprovidedbythesystem
Usecasescanbedescribedtextually,witha
focusontheeventflowbetweenactorand
system
Thetextualusecasedescriptionconsistsof
6parts:
1.
2.
3.
4.
5.
6.
Uniquename
Participatingactors
Entryconditions
Exitconditions
Flowofevents
Specialrequirements.
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
22
TextualUseCase
DescriptionExample
Passenger
1.Name:Purchaseticket
2.Participatingactor:Passenger
3.Entrycondition:
Passengerstandsinfrontof
ticketdistributor
Passengerhassufficient
moneytopurchaseticket
PurchaseTicket
5.Flowofevents:
1.Passengerselectsthe
numberofzonestobetraveled
2.Ticket Distributordisplays
theamountdue
3.Passengerinsertsmoney,at
leasttheamountdue
4.TicketDistributorreturns
change
5.TicketDistributorissuesticket
6.Specialrequirements:None.
4.Exitcondition:
Passengerhasticket
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
23
UsesCasescanberelated
ExtendsRelationship
Torepresentseldominvokedusecasesorexceptionalfunctionality
IncludesRelationship
Torepresentfunctionalbehaviorcommontomorethanoneuse
case.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
24
The<<extends>>Relationship
Passenger
PurchaseTicket
<<extends>>relationshipsmodel
exceptionalorseldominvokedcases
Theexceptionaleventflowsare
factoredoutofthemaineventflowfor
clarity
Thedirectionofan<<extends>>
relationshipistotheextendedusecase
Usecasesrepresentingexceptional
flowscanextendmorethanoneuse
case.
<<extends>>
<<extends>>
<<extends>>
OutOfOrder
<<extends>>
Cancel
BerndBruegge&AllenH.Dutoit
TimeOut
NoChange
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
25
The<<includes>>Relationship
Passenger
PurchaseMultiCard
PurchaseSingleTicket
<<includes>>
<<includes>>
<<extends>>
NoChange
CollectMoney
<<extends>>
Cancel
BerndBruegge&AllenH.Dutoit
<<includes>>relationship
representscommonfunctionality
neededinmorethanoneusecase
<<includes>>behavioris
factoredoutforreuse,notbecauseit
isanexception
Thedirectionofa<<includes>>
relationshipistotheusingusecase
(unlikethedirectionofthe
<<extends>>relationship).
<<extends>>
Cancel
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
26
ClassDiagrams
Classdiagramsrepresentthestructureofthesystem
Used
duringrequirementsanalysistomodelapplicationdomain
concepts
duringsystemdesigntomodelsubsystems
duringobjectdesigntospecifythedetailedbehaviorand
attributesofclasses.
TarifSchedule
Tablezone2price
EnumerationgetZones()
PricegetPrice(Zone)
BerndBruegge&AllenH.Dutoit
Trip
zone:Zone
Price:Price
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
27
Classes
Type
Name
TarifSchedule
zone2price
getZones()
getPrice()
TarifSchedule
Tablezone2price
EnumerationgetZones()
PricegetPrice(Zone)
Attributes
Operations
Signature
TarifSchedule
Aclassrepresentsaconcept
Aclassencapsulatesstate(attributes)andbehavior(operations)
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
28
ActorvsClassvsObject
Actor
Anentityoutsidethesystemtobemodeled,interactingwiththe
system(Passenger)
Class
Anabstractionmodelinganentityintheapplicationorsolution
domain
Theclassispartofthesystemmodel(User,Ticketdistributor,
Server)
Object
Aspecificinstanceofaclass(Joe,thepassengerwhoispurchasing
aticketfromtheticketdistributor).
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
30
Associations
TarifSchedule
TripLeg
EnumerationgetZones()
PricegetPrice(Zone)
Price
Zone
Associationsdenoterelationshipsbetweenclasses
The multiplicity of an association end denotes how many
objects the instance of a class can legitimately reference.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
31
1to1and1tomanyAssociations
Country
name:String
City
name:String
1to1association
Polygon
Point
x: Integer
y: Integer
draw()
1tomanyassociation
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
32
ManytoManyAssociations
StockExchange
BerndBruegge&AllenH.Dutoit
Company
tickerSymbol
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
33
FromProblemStatementToObjectModel
ProblemStatement:Astockexchangelistsmanycompanies.
Eachcompanyisuniquelyidentifiedbyatickersymbol
Class Diagram:
StockExchange *
BerndBruegge&AllenH.Dutoit
Lists
Company
tickerSymbol
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
34
FromProblemStatementtoCode
ProblemStatement :Astockexchangelistsmanycompanies.
Eachcompanyisidentifiedbyatickersymbol
Class Diagram:
StockExchange
Java Code
Lists
Company
tickerSymbol
publicclassStockExchange
{
privateVectorm_Company=newVector();
};
Associations
are mapped to
Attributes!
publicclassCompany
{
publicintm_tickerSymbol;
privateVectorm_StockExchange=newVector();
};
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
35
Aggregation
Anaggregationisaspecialcaseofassociationdenotingaconsistsof
hierarchy
Exhaust system
Theaggregateistheparentclass,
thecomponentsarethechildrenclasses
1
Muffler
diameter
0..2
Tailpipe
diameter
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
36
Inheritance
Button
CancelButton
ZoneButton
Inheritanceisanotherspecialcaseofanassociationdenotinga
kindofhierarchy
Inheritancesimplifiestheanalysismodelbyintroducinga
taxonomy
Thechildrenclassesinherittheattributesandoperationsofthe
parentclass.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
39
Packages
PackageshelpyoutoorganizeUMLmodelstoincreasetheir
readability
WecanusetheUMLpackagemechanismtoorganizeclassesinto
subsystems
Account
Bank
Customer
Anycomplexsystemcanbedecomposedintosubsystems,where
eachsubsystemismodeledasapackage.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
40
ObjectModelinginPractice
Foo
Amount
CustomerId
Deposit()
Withdraw()
GetBalance()
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
41
ObjectModelinginPractice:Brainstorming
Foo
Dada
Amount
Amount
CustomerId
CustomerId
Deposit()
Withdraw()
GetBalance()
Deposit()
Withdraw()
GetBalance()
Account
Amount
CustomerId
BerndBruegge&AllenH.Dutoit
Deposit()
Withdraw()
GetBalance()
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
42
ObjectModelinginPractice:Moreclasses
Account
Amount
AccountId
CustomerId
Bank
Deposit()
Withdraw()
GetBalance()
Name
Customer
Name
CustomerId
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
43
ObjectModelinginPractice:Associations
Account
Bank
?
has
Amount
AccountId
CustomerId
AccountId
owns
Deposit()
Withdraw()
GetBalance()
Name
Customer
2
Name
CustomerId
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
44
PracticeObjectModeling:FindTaxonomies
Account
Bank
Name
Amount
AccountId
CustomerId
AccountId
Customer
Has
Deposit()
Withdraw()
GetBalance()
Savings
Account
Withdraw()
BerndBruegge&AllenH.Dutoit
Name
CustomerId()
Checking
Account
Mortgage
Account
Withdraw()
Withdraw()
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
45
PracticeObjectModeling:Simplify,Organize
Account
Amount
AccountId
CustomerId
AccountId
Deposit()
Withdraw()
GetBalance()
Savings
Account
Withdraw()
BerndBruegge&AllenH.Dutoit
Show Taxonomies
separately
Checking
Account
Mortgage
Account
Withdraw()
Withdraw()
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
46
PracticeObjectModeling:Simplify,Organize
Bank
Name
Account
Amount
AccountId
CustomerId
AccountId
Customer
Has
Deposit()
Withdraw()
GetBalance()
Name
CustomerId()
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
47
Focus on
control flow
SequenceDiagrams
Passenger
TicketMachine
Torefineusecasedescriptions
tofindadditionalobjects
(participatingobjects)
selectZone()
insertCoins()
pickupChange()
BerndBruegge&AllenH.Dutoit
Usedduringsystemdesign
TicketMachine
torefinesubsysteminterfaces
zone2price
Messages ->
Instancesarerepresentedby
selectZone()
Operations on
rectangles.Actorsbystickyfigures
insertCoins()
participating Object
Lifelinesarerepresentedbydashed
pickupChange()
lines
pickUpTicket()
pickUpTicket()
Usedduringanalysis
Messagesarerepresentedbyarrows
Activationsarerepresentedbynarrow
rectangles.
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
48
SequenceDiagramscanalsomodeltheFlowofData
Passenger
ZoneButton
selectZone()
TarifSchedule
Display
lookupPrice(selection)
price
Dataflow
displayPrice(price)
Thesourceofanarrowindicatestheactivationwhichsentthemessage
Horizontaldashedarrowsindicatedataflow,forexamplereturnresults
fromamessage
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
49
SequenceDiagrams:Iteration&Condition
continued from previous slide...
Passenger
ChangeProcessor
*insertChange(coin)
Iteration
Condition
CoinIdentifier
Display
CoinDrop
lookupCoin(coin)
price
displayPrice(owedAmount)
[owedAmount<0]returnChange(owedAmount)
Iterationisdenotedbya*precedingthemessagename
Conditionisdenotedbybooleanexpressionin[]beforethemessage
name
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
50
Creationanddestruction
continued from previous slide...
Passenger
Creation of Ticket
ChangeProcessor
createTicket(selection)
Ticket
print()
free()
Destruction of Ticket
Creationisdenotedbyamessagearrowpointingtotheobject
DestructionisdenotedbyanXmarkattheendofthedestructionactivation
Ingarbagecollectionenvironments,destructioncanbeusedtodenotetheend
oftheusefullifeofanobject.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
51
SequenceDiagramProperties
UMLsequencediagramrepresentbehaviorintermsof
interactions
Usefultoidentifyorfindmissingobjects
Timeconsumingtobuild,butworththeinvestment
Complementtheclassdiagrams(whichrepresentstructure).
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
52
ActivityDiagrams
Anactivitydiagramisaspecialcaseofastatechartdiagram
Thestatesareactivities(functions)
Anactivitydiagramisusefultodepicttheworkflowina
system
Handle
Incident
BerndBruegge&AllenH.Dutoit
Document
Incident
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
Archive
Incident
53
ActivityDiagramsallowtomodelDecisions
Decision
[lowPriority]
Open
Incident
Allocate
Resources
[fire&highPriority]
[notfire&highPriority]
Notify
FireChief
Notify
PoliceChief
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
54
ActivityDiagramscanmodelConcurrency
Synchronizationofmultipleactivities
Splittingtheflowofcontrolintomultiplethreads
Splitting
Open
Incident
Allocate
Resources
Coordinate
Resources
Synchronization
Archive
Incident
Document
Incident
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
55
ActivityDiagrams:GroupingofActivities
Activitiesmaybegroupedintoswimlanestodenotetheobject
orsubsystemthatimplementstheactivities.
Allocate
Resources
Open
Incident
Coordinate
Resources
Dispatcher
Archive
Incident
FieldOfficer
Document
Incident
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
56
ActivityDiagramvs.StatechartDiagram
Statechart Diagram for Incident
Focus on the set of attributes of a single abstraction (object, system)
Event causes
state transition
Active
Inactive
Incident
Handled
Closed
Incident
Documented
Archived
Incident
Archived
Document
Incident
Completion of activity
causes state transition
BerndBruegge&AllenH.Dutoit
Archive
Incident
Triggerless
transition
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
57
UMLSummary
UMLprovidesawidevarietyofnotationsforrepresenting
manyaspectsofsoftwaredevelopment
Powerful,butcomplex
UMLisaprogramminglanguage
Canbemisusedtogenerateunreadablemodels
Canbemisunderstoodwhenusingtoomanyexoticfeatures
Weconcentratedonafewnotations:
Functionalmodel:Usecasediagram
Objectmodel:classdiagram
Dynamicmodel:sequencediagrams,statechartandactivity
diagrams
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
58
AdditionalReferences
MartinFowler
UMLDistilled:ABriefGuidetotheStandardObjectModeling
Language,3rded.,AddisonWesley,2003
CommercialUMLtools
RationalRoseXDEforJava
http://www306.ibm.com/software/awdtools/developer/java/
Together(Eclipse,MSVisualStudio,JBuilder)
http://www.borland.com/us/products/together/index.html
OpenSourceUMLtools
http://javasource.net/opensource/umlmodeling
ArgoUML,UMLet,Violet,
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava
59