Transcript 1..

UML Class Diagram
and a little about Object Diagrams
Class
Association
1
The reality and UML-models
Business processes
(in Activity Diagram)
Communication
between people
(in Sequence Diagram
Business concepts
(in Class Diagram)
Use case
Activity Diagram
Sequens Diagram
Information Model
(in Class Diagram)
The reality
UML-models
2
Class 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:
Student
personalnr
name
email
Course
courseID
courseName
• type och class,
• relation och association,
• structural och static.
In UML-context we should use the
concepts marked in bold letters.
registerForCourse()
3
Classes – 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.
Student
personalnr
name
email
registerForCourse()
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.
4
Classes – variants of notations
Class name
Student
personalnr
name
email
Student
Student
personalnr
name
email
registerForCourse()
requestIncreasedAccount()
Operations
Attributes
5
Classes – objects, attributes & methods
Objects:
Students can have a lot of similarities, for example email, 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.
Student
personalnr
name
email
registerForCourse()
requestIncreasedAccount()
Attributes:
are used to describe static characteristics within a class.
Are given values in their objects.
Operations:
are spoken about at class level when to represent the
dynamic behaviors of the objects. Operations are called
methods at the object level.
6
Class Diagram and Object Diagram
Class
Student
personalnr
name
address
email
Object (instance)
Object (instance)
nilsHall:Student
personalnr = ”850302-XXXX”
name = ”Nils Erik Hall”
address = ”Rågstigen 3”
email = ”[email protected]”
Class Diagram
annaSvan:Student
personalnr = ”770102-XXXX”
name = ”Anna Cecilia Svan”
address = ”Ekvägen 10”
email = ”[email protected]”
Object 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.
7
Attributes & associations are properties
Properties
Associations
Student
Registration
personalnr
name
email
registrationID
date
Course
courseID
courseName
Attributes
Properties
Properties (characteristics)
- is UML’s umbrella term for the attributes and associations of classes.
- models the static (structural) characteristics of classes.
8
Properties have multiplicity
Student
personalnr [1..1]
name [1..1]
email [1..*]
Registration
1..1
0..*
registrationID [1..1]
date [1..1]
Course
0..*
1..1
courseID [1..1]
courseName [0..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.
9
Multiplicity – usual combinations
Student
personalnr [1..1]
name [1..1]
email [1..*]
Course
Registration
1..1
0..*
registrationID [1..1]
date [1..1]
0..*
1..1
courseID [1..1]
courseName [0..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.
10
Multiplicity for associations
Student
personalnr
name
email
Registration
1..1
0..*
registrationID
date
Course
0..*
1..1
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.
11
More about multiplicity for associations
Student
1..1
0..*
Registration
anna:Student
0..*
1..1
Course
oop:Course
9:Registration
nils:Student
2:Registration
oos:Course
6:Registration
tove:Student
jök:Course
12
Multiplicity of associations with Venn-diagram
Student
Registration
Course
9
oop
Anna
2
oos
Nils
6
Tove
jök
13
Notes
 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.
Student
{ Only students
living at IP }
14
Attribute - 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 further
properties of
the attribute.
Automaticly assigned
when an object is
created.
There are publik (+), privat (-),
protected (#) visibility,
and packet visibility (~).
Anställd
+ companynr: Integer [1..1] = 4222 {readOnly}
15
Operationes - 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 returned
value.
Perhaps further
properties of
the operation.
There are publik (+), privat (-),
protected (#) visibility,
and packet visibility (~).
Employee
+ companynr: Integer [1..1] = 4222 {readOnly}
+ getNamn (employeenr:Integer): String
16
UML-concept feature
Features
Staticfeatures
Dynamicfeatures
properties
Attribute
Associations
Operations
17
To name associations
Three ways to name associations:
1) with a verb at each class.
Student
studregnr [1..1]
0..*
is supervising
is supervised
1..*
Teacher
employeenr [1..1]]
18
To name associations
Three ways to name associations:
2) Only one verb at the association line
.
Student
studregnr [1..1]
0..*
Teacher
supervise
1..1
employeenr [1..1]
19
To name associations
Three ways to name associations:
3) With a substantive at each class.
Student
studregnr [1..1]
0..*
thesiswriter
supervisor
1..*
Teacher
employeenr [1..1]
20
Class Diagram – a summary
Classes
Attributes
Student
personalnr [1..1]
name [1..1]
email [1..*]
registerForCourse()
Registration
Associations
1..1
registrationID [1..1]
date [1..1]
0..*
Operations
listRegistrations()
Multiplicity
Includes University
students, but not
secondary school
students.
Notes
.
Objects
annaSvan: Student
personalnr = ”770102-XXXX”
name = ”Anna Cecilia Svan”
email = ”[email protected]”
registerForCourse()
21