1 uml class diagram class association and a little about object diagrams
Post on 19-Dec-2015
233 views
TRANSCRIPT
1
UML Class Diagram
Class
Association
and a little about Object Diagrams
2
The reality and UML-models
Business processes(in Activity Diagram)
Communication between people(in Sequence Diagram
Sequens DiagramActivity Diagram
Use case
The reality UML-models
Business concepts(in Class Diagram)
Information Model (in Class Diagram)
3
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.
Studentpersonalnrnameemail
registerForCourse()
CoursecourseIDcourseName
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.
4
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.
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.
Studentpersonalnrnameemail
registerForCourse()
5
Classes – variants of notations
Class name
AttributesOperations
Studentpersonalnrnameemail
registerForCourse()requestIncreasedAccount()
Studentpersonalnrnameemail
Student
6
Classes – objects, attributes & methods
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.
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.
Studentpersonalnrnameemail
registerForCourse()requestIncreasedAccount()
7
Class Diagram and Object Diagram
Studentpersonalnrnameaddressemail
annaSvan:Studentpersonalnr = ”770102-XXXX”name = ”Anna Cecilia Svan”address = ”Ekvägen 10”email = ”[email protected]”
nilsHall:Studentpersonalnr = ”850302-XXXX”name = ”Nils Erik Hall”address = ”Rågstigen 3”email = ”[email protected]”
Object DiagramClass 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.
Class Object (instance)Object (instance)
8
Attributes & associations are properties
Studentpersonalnrnameemail
Course
courseIDcourseName
RegistrationregistrationIDdate
Properties (characteristics)
- is UML’s umbrella term for the attributes and associations of classes.
- models the static (structural) characteristics of classes.
Associations
Attributes
Properties
Properties
9
Properties have multiplicity
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.
Studentpersonalnrnameemail
Course
courseIDcourseName
RegistrationregistrationIDdate
0..*1..1 0..* 1..1[1..1][1..1][1..*]
[1..1][1..1]
[1..1][0..1]
10
Multiplicity – usual combinations
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.
Studentpersonalnrnameemail
Course
courseIDcourseName
RegistrationregistrationIDdate
0..*1..1 0..* 1..1[1..1][1..1][1..*]
[1..1][1..1]
[1..1][0..1]
11
Multiplicity for associations
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.
Studentpersonalnrnameemail
Course
courseIDcourseName
RegistrationregistrationIDdate
0..*1..1 0..* 1..1
12
More about multiplicity for associations
Student CourseRegistration0..*1..1 0..* 1..1
anna:Student
nils:Student
9:Registration
2:Registration
oop:Course
oos:Course
jök:Coursetove:Student6:Registration
13
Multiplicity of associations with Venn-diagram
Anna
Nils
Tove
Registration
6
2
9
Student Course
oop
oos
jök
14
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.
StudentIncludes University students, but not secondary school students.
{ Only students living at IP }
15
Attribute - notation
visibility name type multiplicity = default value {property}
Anställd+ companynr: Integer [1..1] = 4222 {readOnly}
There are publik (+), privat (-), protected (#) visibility, and packet visibility (~).
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
Automaticly assignedwhen an object is created.
Perhaps furtherproperties of the attribute.
16
Operationes - notation
visibility name (parameter list) : return type {property}
Employee
+ getNamn (employeenr:Integer): String
+ companynr: Integer [1..1] = 4222 {readOnly}
There are publik (+), privat (-), protected (#) visibility, and packet visibility (~).
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.
17
UML-concept feature
Attribute OperationsAssociations
properties
Features
DynamicStaticfeatures features
18
To name associations
Three ways to name associations:1) with a verb at each class.
Student Teacher0..*
1..* employeenr [1..1]]studregnr [1..1] is supervising
is supervised
19
To name associations
Three ways to name associations:2) Only one verb at the association line
.
Student Teacher0..*
1..1 employeenr [1..1]studregnr [1..1] supervise
20
To name associations
Three ways to name associations: 3) With a substantive at each class.
Student Teacher0..*
1..* employeenr [1..1]studregnr [1..1] thesiswriter
supervisor
21
Class Diagram – a summary
Classes
Attributes
Operations
Associations
annaSvan: Studentpersonalnr = ”770102-XXXX”name = ”Anna Cecilia Svan”email = ”[email protected]”
Multiplicity
registerForCourse()
Objects
Notes
Studentpersonalnrnameemail
Registration
0..*1..1
[1..1][1..1][1..*]
[1..1][1..1]
registrationIDdate
registerForCourse() listRegistrations()
Includes University students, but not secondary school students.
.