Title: UML Class Diagram
1UML Class Diagram
and a little about Object Diagrams
Class
Association
2The reality and UML-models
The reality
UML-models
3Class Diagrams central in UML
The Class Diagrams are the majority have almost
become synonymous with UML. Class Diagrams
describes Classes in a domain or in a system, and
static associations between the classes. Class
Diagrams also shows the attributes and operations
of the classes.
- Note that following words have been used as
synonymes - type och class,
- relation och association,
- structural och static.
- In UML-context we should use the concepts marked
in bold letters.
4Classes UML-notation
- The UML-notation for a class is a rectangle with
(normally) three sections or compartments. - the compartment at the top contains the name of
the class in bold letters and a capital
first letter. - the compartment in the middle contains the names
of the attributes in the class. - the compartment at the bottom contains the names
of the operations in the class.
Note the way to write the names of the attributes
and operations yet a convention and no formal
rules - begins with a small letter, a capital
letter can be placed in the middle if it consists
of several words. - name of the class and names
of the attributes are written as substantives or
substantive phrases, names of classes begin with
a capital letter. - operations are written as
verbs, also note the parentheses after the
operation name.
Student
personalnr name email
registerForCourse()
5Classes variants of notations
Class name
Attributes
Operations
6Classes objects, attributes methods
Objects Students can have a lot of similarities,
for example e-mail, and they can register for
courses. We collect similarities and create the
class Student. Every student is now an object of
the class Student. All Student objects have a
value on the attributes and are able to perform
the methods.
Attributesare used to describe static
characteristics within a class. Are given values
in their objects.
Operationsare spoken about at class level when
to represent the dynamic behaviors of the
objects. Operations are called methods at the
object level.
7Class Diagram and Object Diagram
Class
Object (instance)
Object (instance)
annaSvanStudent
Student
nilsHallStudent
personalnr name address email
personalnr 770102-XXXX name Anna Cecilia
Svan address Ekvägen 10 email
sva_at_dsv.su.se
personalnr 850302-XXXX name Nils Erik
Hall address Rågstigen 3 email
hal_at_dsv.su.se
Object Diagram
Class Diagram
Often called Instance Diagram. Increased notation
för naming. Attributes gets values. All
associationes from the Clas Diagram follows to
the objects. Can be seen as a snapshot of one or
more objects at a certain moment. Why? The values
of the attributes can be changed during the
lifecycle of the objects.
8Attributes associations are properties
Properties
Associations
Student
Course
Registration
personalnr name email
registrationID date
courseID courseName
Attributes
Properties
- Properties (characteristics)
- is UMLs umbrella term for the attributes and
associations of classes. - models the static (structural) characteristics
of classes.
9Properties have multiplicity
Student
Course
Registration
0..
1..1
0..
1..1
personalnr name email
registrationID date
1..1
1..1
courseID courseName
1..1
1..1
1..1
0..1
1..
The multiplicity for a property (attribute or
association) indicates how many different objects
(or values) that are able to fulfil the
property. Multiplicity for associations is stated
at each assoiciated class. The complete way to
write multiplicity , is that - the smallest
number is stated first, - the largest number is
stated last, - two dots are written between the
numbers.
10Multiplicity usual combinations
Student
Course
Registration
0..
1..1
0..
1..1
personalnr name email
registrationID date
1..1
1..1
courseID courseName
1..1
1..1
1..1
0..1
1..
1..1 Minimum 1 and maximum 1.
Example A student has one, and only
one, value at the attribute
personalnr. 1.. Minimum 1 and an infinite upper
number. Example A student is always given
one e-mail address, but
can
have many more e-mails. 0.. 0 is
valid and an infinite upper number.
Example A student does not have to
be registered on a course, but can
be
registered on many courses. 0..1 0 is valid
and maximum 1. Example
A course does not need to
have been given a name and can
possibly have one name.
11Multiplicity for associations
Student
Course
Registration
0..
1..1
0..
1..1
personalnr name email
registrationID date
courseID courseName
multiplicity describes how many different objects
that can be part of an association between two
classes. Exemple A Student object is
associated to zero-to-many Registrations. A
Registration object is associated to one-to-one,
i.e. exactly one, Student.
12More about multiplicity for associations
Student
Course
Registration
0..
1..1
0..
1..1
annaStudent
oopCourse
9Registration
nilsStudent
2Registration
oosCourse
6Registration
jökCourse
toveStudent
13Multiplicity of associations with Venn-diagram
Registration
Student
Course
9
oop
Anna
2
oos
Nils
6
jök
Tove
14Notes
- Notes is comments in UML-diagrams.
- Not connected to any special modelling element
- If notes is about a special modelling element it
is connected to the element with a broken line.
Note that the line ends with a small unfilled
circle. - Notes can also be used to state constraints for
the modelling element. The constraints then have
to be written within curly braces. Constraints
can also be written in text or more formally.
Includes University students, but not secondary
school students.
Only students living at IP
Student
15Attribute - notation
visibility name type multiplicity default value
property
The only mandatory part in the notation of the
attribute.
The data type of the value. Limits which type of
values the attributes can have.
Multiplicity
Perhaps furtherproperties of the attribute.
Automaticly assignedwhen an object is created.
There are publik (), privat (-), protected ()
visibility, and packet visibility ().
16Operationes - notation
visibility name (parameter list) return type
property
The only mandatory part in the notation of the
operation.
List of the parameters used by the operation.
It can be input (in), output (out), or both
(inout).
The data type of the returnedvalue.
Perhaps furtherproperties of the operation.
There are publik (), privat (-), protected ()
visibility, and packet visibility ().
17UML-concept feature
Features
Dynamic
Static
features
features
properties
Operations
Attribute
Associations
18To name associations
Three ways to name associations 1) with a verb
at each class.
Teacher
Student
0..
is supervised
employeenr 1..1
studregnr 1..1
is supervising
1..
19To name associations
Three ways to name associations2) Only
one verb at the association line .
Student
Teacher
0..
supervise
employeenr 1..1
studregnr 1..1
1..1
20To name associations
Three ways to name associations 3) With a
substantive at each class.
Teacher
supervisor
Student
0..
employeenr 1..1
studregnr 1..1
thesiswriter
1..
21Class Diagram a summary
Classes
Attributes
Registration
Student
Associations
personalnr name email
1..1
1..1
registrationID date
1..1
1..1
0..
1..1
1..
Operations
registerForCourse()
listRegistrations()
Multiplicity
Includes University students, but not secondary
school students. .
annaSvan Student
Notes
personalnr 770102-XXXX name Anna Cecilia
Svan email sva_at_dsv.su.se
Objects
registerForCourse()