Introduction To Unified Modeling Language (UML)
Introduction To Unified Modeling Language (UML)
Language (UML)
6-2
2
UML
6-5
5
First up: Class Diagrams
A class diagram
expresses class definitions to be implemented
lists name, attributes, and methods for each class
shows relationships between classes
UML allows different levels of detail on both
the attributes and the methods of one class
could be just the the class name in a rectangle
or like the general form shown on the next slide
6-6
6
Software Specification (Class Name)
attribute
attribute : type
attribute : type = initial value
classAttribute
derivedAttribute
...
method1()
method2(parameter : Type) : return type
abstractMethod()
+publicMethod()
-privateMethod()
#protectedMethod()
classMethod()
...
6-7
7
AccountCollection
- allAccounts : HashMap
+AccountCollection ()
+getAccountWithID (ID: String) : Account
+add(accountToAdd: Account) : boolean
+iterator() : Iterator
6-8
8
Sterotypes
6-9
9
Different levels of detail
6-10
10
Relationships
6-11
11
1) Dependency: A Uses Relationship
Dependencies
occurs when one object depends on another
if you change one object's interface, you need to
change the dependent object
arrows point from dependent to needed objects
CardReader
Jukebox
CDCollection
SongSelector
6-12
12
2)Association: Structural Relationship
Association
a relationship between classes indicates some
meaningful or interesting connection
Associations can be labeled getAccountWithID for example
BTW: The box with association is an official UML comment, must have that fold
association
getAccountWithID
Jukebox JukeboxAccountCollection
1 1
6-13
13
Associations
Associations imply
our knowledge that a relationship must be
preserved for some time (0.01 ms to forever)
Between what objects do we need to remember a
relationship?
• Does a Transaction need to remember Account?
• Would AccountCollection need to remember
Accounts?
Stores
AccountCollection Account
1 0..*
6-14
14
Notation and Multiplicity Adornments
UML Association:
a line between two concepts and a name
they are bi-directional * T
zero or more;
"many"
can have a multiplicity
exist in class diagrams 1..*
T one or more
1..52
T one to fifty two
5
Multiplicity T exactly five
adornments
6-15
15
Association
Names • Read these Type-VerbPhrase-Type
• POST is a Point of Sale Terminal)
Store • Not shown here: Attributes and Methods
1
• This just shows associations between objects
Contains
1.. *
POST Captures Sale Paid-by Payment
1 1.. * 1 1
Airline
1
Employs
1.. *
Assigned-to Assigned-to
Person Flight Plane
1 * * 1
1 *
6-16
16
Supervises
Aggregation: A Special Association
*
Student
Model aggregation or composition? When in doubt, use
association (just a simple line) don't sweat the diff in 335
6-18
18
Active Learning
6-19
19
Assignment #5, due 3-Sep 4:45 pm
Draw rectangles for classes
Include the class name
In at least five classes, write one
Draw associations between objects
missing diamonds and arrows are okay
one solid line will suffice
an association implies there will be some
relationship between the objects as some point
There is a separate handout for this
You must be in class to get credit
6-20
20
Sequence Diagrams
Interaction diagrams describe how groups of objects
collaborate in some behavior
The UML defines several forms of interaction
diagram, the most common is the sequence diagram
A class diagram shows a fixed view of a system
A sequence diagram represents a dynamic view of a
system by capturing message sends over time
Can document a scenario such as
Dealer deals cards to all players
Withdraw Money when there is enough balance
Withdraw Money when there is not enough balance
6-21
21
6-22
22
Sequence Diagrams
6-23
23
More Distributed Control Shown here
6-24
24
Syntax
Objects are lined up on top in rectangles
Object names :CardReader
Dashed lines represent lifetime of objects
Rectangles are activation lines
When the object is "alive"
Activation bar of the receivers of the message is
smaller than the sender's activation bar
Not much detail written
6-25
25
Another Example
http://www.ifi.uio.no/in219/verktoy/doc/html/doc/user/mg/dgmsuml6.html
Scenario: The user tries to use an ATM, but the account is not known
6-26
26
http://www.visual-paradigm.com/
VPGallery/diagrams/Sequence.html
6-27
27