Unified Modeling Language (UML) Class Diagram & Sequence...
Transcript of Unified Modeling Language (UML) Class Diagram & Sequence...
Class DiagramSequence Diagram
Unified Modeling Language (UML)Class Diagram & Sequence Diagram
Miaoqing HuangUniversity of Arkansas
Spring 2011
1 / 23
Class DiagramSequence Diagram
Outline
1 Class Diagram
2 Sequence Diagram
2 / 23
Class DiagramSequence Diagram
Outline
1 Class Diagram
2 Sequence Diagram
3 / 23
Class DiagramSequence Diagram
Class Diagram
Class diagrams show the static structure of the classes thatmake up a system or subsystemUse case diagrams show the functional requirements of a system(or subsystem) from the perspective of the end-user of a system
4 / 23
Class DiagramSequence Diagram
Classes
Classes are shown as rectanglesClass nameOther compartments
AttributesOperationsOther predefined compartments
Name conventionClass’ name
Have no space between multiple wordsCapitalize the first letter in eachsubsequent world
Name of features in compartmentsHave no space between multiple wordsCapitalize the first letter in eachsubsequent world except the first world
5 / 23
Class DiagramSequence Diagram
Associations among classesAssociations represent relationships between(instances of) classes
Classes collaborate with each other by passingmessages and receiving responses
Association nameIndicates the nature of the associationAssociate name should begin with a capital letterNavigability: use arrow to indicate how to interpretthe association
Unidirectional associationBidirectional association: without arrow
Role nameIndicate the role played by a class in anassociationAttached to the corresponding association endCan use the same rule of naming features to namethe role, i.e., low case the very first letter andcapitalize the first letter of subsequent word
6 / 23
Class DiagramSequence Diagram
Multiplicity
Multiplicity indicates how many objects may participate in thegiven relationship (during the run-time of your software system)
*: 0..infinity1: 1..1n..m: low_bound..up_bound
Multiplicity of an association end is not shownThe multiplicity is not knownThe multiplicity is not specified
7 / 23
Class DiagramSequence Diagram
Aggregation
Aggregation symbol.Assembly consists of components.Component is part of an assembly
Aggregation associationAn instance of one class may consist of instances of another classwhole-part association
whole is made up of parts
Use a solid line with an unfilled diamond shape at the endDiamond is connected to the class that is the aggregate
A part is capable of existing outside of whole-part association8 / 23
Class DiagramSequence Diagram
Composition
Document
SectionFrontMatter Index1 0..1
0..11..*
1..*
Document
FrontMatter [1]
Section [1..*]
Index [0..1]0..1
1..*
Composition associationwhole-part association
The life-cycle of the ‘part’ cannot extend beyond the life-cycle of the‘whole’
Two different notationsFilled diamond notationGraphical containment
9 / 23
Class DiagramSequence Diagram
Generalization
Generalization relationship is(sometimes) described as being a kindof relationship
Generalized class: superclass(supertype)Specialization: subclass (subtype)
Generalization allows the inheritance ofthe attributes and operations of asuperclass by its subclasses
Subclass can override the operations inthe superclass
10 / 23
Class DiagramSequence Diagram
More on attribute and operation
Attribute and Operation Typesfeature-name : type
Attribute and Operation Visibilityprivate (-)
The feature is available only within the class that owns the featurepublic (+)
The feature is available to any class associated with the class thatowns the feature
protected (#)The feature is available within the class that owns that feature andany subtype of that class
package (∼)The feature is available only to other classes in the same package
11 / 23
Class DiagramSequence Diagram
Outline
1 Class Diagram
2 Sequence Diagram
12 / 23
Class DiagramSequence Diagram
Purpose of Sequence Diagram
Static diagramUse case diagrams show the static relationship between actorsand use casesClass diagrams show the static relationship between classes orinstances
A program is a sequence of interactions among objects (i.e.,instances of classes)
Difficult to understand a program only with static diagramsPurpose of sequence diagram
Model the high-level interactions between active objects in asystemModel the high-level interactions between subsystems
13 / 23
Class DiagramSequence Diagram
Sequence Diagram Example
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
14 / 23
Class DiagramSequence Diagram
NotationFrame
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
Sequence diagrams aredrawn in frames
New in UML 2.0
Time runs verticallyLifelines are arrangedhorizontally
Represent object instances
15 / 23
Class DiagramSequence Diagram
NotationFrame
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
Sequence diagrams aredrawn in frames
New in UML 2.0
Time runs verticallyLifelines are arrangedhorizontally
Represent object instances
16 / 23
Class DiagramSequence Diagram
NotationLifeline
Participating instances are represented bylifelines
Dashed vertical lineRectangle representing an object
Syntax Explanationo An object named oo : C An object named o of class C:C An anonymous object of class C
17 / 23
Class DiagramSequence Diagram
NotationMessages and Activation box
A message is shown using an arrow going from the sender to thereceiver
Different types of messagesSynchronous
The sender waits until the reply is receivedAsynchronous
The sender does not wait for the reply; instead, it carries on the nextstep in its own sequence
CreationA message causes the creation of an object instance to which themessage is sent
Reply
18 / 23
Class DiagramSequence Diagram
NotationMessages and Activation box
A message is shown using an arrow going from the sender to thereceiverDifferent types of messages
SynchronousThe sender waits until the reply is received
AsynchronousThe sender does not wait for the reply; instead, it carries on the nextstep in its own sequence
CreationA message causes the creation of an object instance to which themessage is sent
Reply
19 / 23
Class DiagramSequence Diagram
Sequence Diagram Example with Explicit Reply
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
20 / 23
Class DiagramSequence Diagram
NotationCombined Fragments
A sequence of messages can be combined into a fragmentLoop, branches, ...
:Journeyfirst:CarSharer
:SharingAgreement
:RecordAgreementControl
:RecordAgreementUI
CarMatchAdministrator
new agreementdetails set create sharing
agreement
get car sharer ID
find by ID
get journey ID
find by ID
add journey set sharingagreement
set first arranged
loop [i=1..no of car sharers]
sd Create new agreement
21 / 23
Class DiagramSequence Diagram
NotationCombined Fragments
:ReliableDistributor:Order
dispatch
loop [ for each item ]
:NormalDistributor
dispatch
alt [ value > $10,000 ]
[ else ]
22 / 23
Class DiagramSequence Diagram
Exercise
Lay out the lifelines for instances of the classes Student, EnrollInSeminar,SecurityLogon, StudentDatabase, and Seminar. Add the followingmessages to the diagram. Note, keep the order of the messages.
1 Request to enroll to seminar A2 Create an instance of SecurityLogon class3 Provide name4 Provide student number5 Provide password6 Verify the student (name, number, password)7 Return verification result8 Return the student information9 Add the student into the seminar A10 Confirmation of enrollment of seminar A11 Display the confirmation to student
Note: EnrollInSeminar class is both the main control and the main interfacewith the student
23 / 23