Unified Unified Modeling Modeling Language Language Luciano Baresi Luciano Baresi
UnifiedUnifiedModelingModeling
LanguageLanguage
Luciano BaresiLuciano Baresi
Computer SystemComputer System
“A model captures all“A model captures allessential details of a systemessential details of a system””
Dr. James James RumbaughRumbaugh
Visual ModelingVisual Modeling
Business ProcessBusiness Process
requestrequest
orderorder
deliverydelivery
ContributionsContributionsHarelHarel
StatechartsStatechartsMeyerMeyer
Before and after Before and after conditionsconditions
Gamma, et alGamma, et al
Frameworks and patterns,Frameworks and patterns,
HP FusionHP Fusion
Operation descriptions and Operation descriptions and message numberingmessage numbering
EmbleyEmbley
Singleton classes andSingleton classes andhighhigh--level viewlevel view
WirfsWirfs--BrockBrock
ResponsibilitiesResponsibilities
OdellOdell
ClassificationClassification
Shlaer Shlaer -- MellorMellor
Object lifecyclesObject lifecycles
RumbaughRumbaugh
OMTOMT
BoochBooch
Booch methodBooch method
JacobsonJacobson
OOSEOOSE
UML DiagramsUML Diagrams
�� Static viewsStatic viewshhUse case diagramUse case diagramhhClass diagramClass diagramhhObject diagramObject diagramhhComponent diagramComponent diagramhhDeployment diagramDeployment diagram
�� Dynamic viewsDynamic viewshhSequence diagramSequence diagramhhCollaboration diagramCollaboration diagramhhStatechart diagramStatechart diagramhhActivity diagramActivity diagram
Use Case Diagrams Use Case Diagrams
Modeling ElementsModeling Elements
�� Actor: it is a user (human being) or Actor: it is a user (human being) or external system that:external system that:hhExchanges data with the systemExchanges data with the system
�� Provides inputs to and/or receives outputs Provides inputs to and/or receives outputs from the systemfrom the system
�� Use case: it is a functional entity the Use case: it is a functional entity the system is composed of:system is composed of:hh It identifies a feature that the system will It identifies a feature that the system will
provideprovide
Foundamental RelationshipsFoundamental Relationships
�� Interacts Interacts means that there is a link means that there is a link between the actor and use casebetween the actor and use case
�� UsesUses identifies the use of a given identifies the use of a given functionality (it is usefull to stress functionality (it is usefull to stress similiar features in different contexts)similiar features in different contexts)
�� ExtendsExtends defines a case as extension defines a case as extension with respect to a base one (it is the with respect to a base one (it is the way these diagrams use inheritance)way these diagrams use inheritance)
<uses>
User
Manager ATM Machine
Desk
ContextContext
�� The first use case diagram The first use case diagram defines the context of the defines the context of the systemsystem
�� Different choices imply Different choices imply hhDifferent actorsDifferent actorshhDifferent casesDifferent cases
Change Course
Request for Students
Professor
Select Course
Manage Professors
Manage Students
Repository
Manage Courses
Request for courses
Change chosen courses
Student
Register for a courseAccounting Office
... A Simple University... A Simple University
Customer
Manager
Credit definition
Order Order through the Internet
extends
Customer Info
uses
Product Availability
uses
Payment Terms
uses
uses
Another ExampleAnother Example
User ScenariosUser Scenarios
�� A scenario is an instance of a use caseA scenario is an instance of a use casehh It is a specific execution of the use caseIt is a specific execution of the use casehh It defines events and actions for the specific “execution”It defines events and actions for the specific “execution”
�� Scenarios define lowerScenarios define lower--level requirements than use case level requirements than use case diagramsdiagrams
�� Scenarios are usually defined using natural languageScenarios are usually defined using natural language�� UML proposes a more specialized notationUML proposes a more specialized notation
Interaction diagramsInteraction diagrams
Interaction DiagramsInteraction Diagrams
Interaction DiagramsInteraction Diagrams
�� Define the dynamic behavior of a set of objects that Define the dynamic behavior of a set of objects that cooperate for a common goalcooperate for a common goal
�� Are used to “formalize” scenarios in terms ofAre used to “formalize” scenarios in terms ofhhEntities (objects)Entities (objects)hhMessages (methods)Messages (methods)
�� UML offers two different kinds of interaction UML offers two different kinds of interaction diagrams diagrams hhSequence diagramsSequence diagramshhCollaboration diagramsCollaboration diagrams
Goofy Selector
Choose Comp. Science
Available?
Add Goofy
Acknowledge registration
Sequence DiagramsSequence Diagrams
Comp. Science
Sequence DiagramsSequence DiagramsCaller User Means Called User
StartTone
Dial
...
Route
Wait Ring
Answer
Ready Ready
ab
c
d
d’
{b{b--a < 1 sec.}a < 1 sec.}{c{c--b < 10 sec.}b < 10 sec.}
{d’{d’--d < 5 sec.}d < 5 sec.}
The delay comes The delay comes from the networkfrom the network
Now they can start Now they can start chattingchatting
Collaboration DiagramsCollaboration Diagrams
�� Are very close to sequence diagramsAre very close to sequence diagrams�� Highlight the interactions among parts of the same Highlight the interactions among parts of the same
object, instead of among different objectsobject, instead of among different objectshhThey better model messagesThey better model messages
�� Sequences must be modeled explicitely. They do not Sequences must be modeled explicitely. They do not come from reading the diagram in the “usual” waycome from reading the diagram in the “usual” wayhhMessages must be numbered using a dotMessages must be numbered using a dot--like notationlike notation
Collaboration DiagramsCollaboration Diagrams
:Selector1: Before
true
2: Before
Software Eng.
Comp. Science: Course
Another ExampleAnother Example
:Selector
info:AccountingInfo
folder:StudentFolder
Goofy
1: Select 4 courses
2: Select Comp. Science3: Select Soft. Eng.4: Select Physics
5: Select Web Design
6: Select 2 more courses
7: Select Chemistry8: Select History
9: Submit courses
10: Available11: Add Goofy
12: Create Folder
13: Create Accounting Info
Course:Course
Class DiagramsClass Diagrams
Class DiagramsClass Diagrams
�� Define THE static view of a system in terms ofDefine THE static view of a system in terms ofhhClassesClasseshhRelationships among classes:Relationships among classes:
�� Associations (uses)Associations (uses)�� Generalizations (inheritance)Generalizations (inheritance)�� Aggregations (part of)Aggregations (part of)
�� Are the basic elements of all object systemsAre the basic elements of all object systems
ClassesClasses(Visibility)(Visibility)
ProfessorProfessor
+ name: String# surname: String - age: integer = 33
+ visualize()- setCourse()
Professor
name: Stringsurname: Stringage: integer
visualize()setCourse()
Professor
namenamesurnamesurname
ProfessorProfessor
ageage
idid namenamesurnamesurname
ProfessorProfessor
ageage
WellWell--formed Classesformed Classes
�� All object have their own identity. We do not need to All object have their own identity. We do not need to add it to all classes we designadd it to all classes we design
Derived AttributesDerived AttributesPersonPerson
dateOfBirthdateOfBirth: Date: Date/ age :age : intint
DepartmentDepartment
1..*1..*
PersonPerson1..*1..*
worksworks
1..*1..*
/ / employsemploys{age = today {age = today -- dateOfBirthdateOfBirth}}
CompanyCompany
AssociationsAssociations
�� Define bidirectional information channels among Define bidirectional information channels among classesclasses
�� Multiplicity defines the number of instances that are Multiplicity defines the number of instances that are involved in a given associationinvolved in a given association
�� Links are association instancesLinks are association instanceshhA link connects two objectsA link connects two objectshhAn association connects two classesAn association connects two classes
CourseCourse StudentFolderStudentFolderappearsappears
AssociationsAssociations
�� Indicate relationships among classesIndicate relationships among classeshhAn employ that works in a companyAn employ that works in a company
�� Can be labelledCan be labelledhhThe label is usually a verbThe label is usually a verb
CourseCourse StudentStudent3 .. 103 .. 100..*0..*
MultiplicityMultiplicity
�� States how many objects are involved in an States how many objects are involved in an associationassociationhhThe minimum and maximum number of involed objectsThe minimum and maximum number of involed objects
�� States whether the association is mandatoryStates whether the association is mandatory
takestakes
MultiplicityMultiplicity
11Exactly 1Exactly 1
** Zero or moreZero or more
0..10..1 Zero or oneZero or one
m..nm..n From m to nFrom m to n
CourseCourse CurriculumCurriculum1..*1..*
AggregationsAggregations
�� Aggregations are specialAggregations are special--purpose associations. They purpose associations. They must be used when an object must be used when an object containscontains other objects other objects ((partpart--ofof))
SliderSliderPanelPanel ButtonButton
WindowWindow
1
2
1
1
1
1scrollbarscrollbar
bodybody closeclose22
11 11
11
11
11
CompositionsCompositions
�� Compositions are stronger aggreations Compositions are stronger aggreations hhParts cannot live alone; They depend on their containerParts cannot live alone; They depend on their container
containscontains
CourseCourse
precedesprecedes
PartPart
Reflexive AssociationsReflexive Associations
�� Un’associazione è riflessiva se coinvolge oggetti della Un’associazione è riflessiva se coinvolge oggetti della stessa classestessa classe
�� Indicano oggetti multipli della stessa classe che sono Indicano oggetti multipli della stessa classe che sono in relazione fra loroin relazione fra loro
PersonPerson
StudentStudent ProfessorProfessor
Inheritance (Generalization)Inheritance (Generalization)
�� Makes explicit common Makes explicit common behaviorsbehaviors
�� Could require:Could require:hhThe addiction of new The addiction of new
propertiespropertieshhThe modification of The modification of
existing operationsexisting operations
Abstract ClassesAbstract Classes
PolygonPolygon CircleCircle
ShapeShape
TriangleTriangle SquareSquare
Statechart DiagramsStatechart Diagrams
Statechart DiagramsStatechart Diagrams
�� Define the interal behavior of single objects (classes) Define the interal behavior of single objects (classes) in terms ofin terms ofhhEvents to which objects are sensible toEvents to which objects are sensible tohhProduced actionsProduced actionshhState transitionsState transitions
�� They are used to identify internal statesThey are used to identify internal states
�� Describe parallel and concurrent activitiesDescribe parallel and concurrent activities�� Come from statecharts by D. HarelCome from statecharts by D. Harel
StateChartsStateCharts
StateState OR DecompositionOR Decomposition
AND DecompositionAND Decomposition
eventeventactionaction
TransitionTransition
A Simple InteractionA Simple Interaction
EmptyEmpty
TankTank
ClosedClosed
ONONOpenOpen
Fornello
fillfill
FullFull
[gas = 0][gas = 0]
[gas > 0][gas > 0]
openopen
[tank.state == full][tank.state == full]
closeclose
sparkspark
Neutral Reverse
Forward
Low Mid High
R
N
F N
Pick up Pick up
Slow downSlow down
stop
Automatic transmission
Or DecompositionOr Decomposition
�� A macro state means an or decomposition among statesA macro state means an or decomposition among states�� All subAll sub--states inherit the transitions to/from their superstates inherit the transitions to/from their super--statesstates
And DecompositionAnd Decomposition
Naturallyattentive
do: take notes
do: yawn
do: scratch
Inattentive
boredwarning
Forcedlyattentivedo: drawwarning
Activity DiagramsActivity Diagrams
StartStart
Synchronization barSynchronization bar
EndEnd
*ActivityActivity
DecisionDecision
Iterated eventIterated event
success labellabel
Syntactical ElementsSyntactical Elements
An exampleAn exampleReceiveOrder
CheckPayment
CheckAvailability
DeleteOrder
Assign toOrder
ReorderElements
CompleteOrder
* For all elements
failure
success
All pieces available
Other DiagramsOther Diagrams
�� UML offers several other diagramsUML offers several other diagrams�� They are implementationThey are implementation--oriented diagramsoriented diagrams�� They are necessary fromThey are necessary from
hhA complete view of UMLA complete view of UMLhhA complete software processA complete software process
�� They are not covered in this course becauseThey are not covered in this course becausehhWe cover mainly requirementsWe cover mainly requirementshhWe do not exemplify the whole software processWe do not exemplify the whole software process
ReferencesReferences
�� The unified modeling The unified modeling language user guidelanguage user guideG. Booch, J. Rumbaugh e I. G. Booch, J. Rumbaugh e I. JacobsonJacobsonaddison wesley, 1998addison wesley, 1998
�� The modeling language The modeling language reference manualreference manualJ. Rumbaugh, I. Jacobson e J. Rumbaugh, I. Jacobson e G. Booch G. Booch addison wesley, 1999addison wesley, 1999
�� The unified software The unified software development processdevelopment processI. Jacobson, G. Booch e J. I. Jacobson, G. Booch e J. RumbaughRumbaugh
�� UML distilledUML distilledM. Fowler e K. ScottM. Fowler e K. Scottaddison wesley, 1999addison wesley, 1999
�� Http://www.Rational.ComHttp://www.Rational.Com�� Http://www.Omg.OrgHttp://www.Omg.Org
Any Questions? Any Questions?
Luciano BaresiLuciano BaresiDEI DEI -- Politecnico di MilanoPolitecnico di Milano
Piazza L.Piazza L. dada Vinci, 32 Vinci, 32 -- 20133 Milano (Italia)20133 Milano (Italia)teltel: 0223993638 : 0223993638 -- email:email: baresibaresi@@eletelet..polimipolimi.it.it