UML Class Diagram and a little about Object

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 course. ID course. Name • type och class, • relation och association, • structural och static. In UML-context we should use the concepts marked in bold letters. register. For. Course() 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 register. For. Course() 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 register. For. Course() request. Increased. Account() 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 register. For. Course() request. Increased. Account() 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) nils. Hall: Student personalnr = ” 850302 -XXXX” name = ”Nils Erik Hall” address = ”Rågstigen 3” email = ”hal@dsv. su. se” Class Diagram anna. Svan: Student personalnr = ” 770102 -XXXX” name = ”Anna Cecilia Svan” address = ”Ekvägen 10” email = ”sva@dsv. su. se” 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 registration. ID date Course course. ID course. Name Attributes 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. Properties have multiplicity Student personalnr [1. . 1] name [1. . 1] email [1.](http://slidetodoc.com/presentation_image_h2/48444408595ca5258f907cbba798b067/image-9.jpg)
Properties have multiplicity Student personalnr [1. . 1] name [1. . 1] email [1. . *] Registration 1. . 1 0. . * registration. ID [1. . 1] date [1. . 1] Course 0. . * 1. . 1 course. ID [1. . 1] course. Name [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 Multiplicity – usual combinations Student personalnr [1. . 1] name [1. . 1] email](http://slidetodoc.com/presentation_image_h2/48444408595ca5258f907cbba798b067/image-10.jpg)
Multiplicity – usual combinations Student personalnr [1. . 1] name [1. . 1] email [1. . *] Course Registration 1. . 1 0. . * registration. ID [1. . 1] date [1. . 1] 0. . * 1. . 1 course. ID [1. . 1] course. Name [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 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. . * registration. ID date Course 0. . * 1. . 1 course. ID course. Name 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 anna: Student nils: Student 1. . 1 0. . * Registration 9: Registration 2: Registration 0. . * 1. . 1 Course oop: Course 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 n Notes is comments in UML-diagrams. n Not connected to any special modelling element n 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. n 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 {read. Only} 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 {read. Only} + get. Namn (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] Teacher 0. . * 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. Class Diagram – a summary Classes Attributes Student personalnr [1. . 1] name [1.](http://slidetodoc.com/presentation_image_h2/48444408595ca5258f907cbba798b067/image-21.jpg)
Class Diagram – a summary Classes Attributes Student personalnr [1. . 1] name [1. . 1] email [1. . *] register. For. Course() Registration Associations 1. . 1 registration. ID [1. . 1] date [1. . 1] 0. . * Operations list. Registrations() Multiplicity Includes University students, but not secondary school students. Notes . Objects anna. Svan: Student personalnr = ” 770102 -XXXX” name = ”Anna Cecilia Svan” email = ”sva@dsv. su. se” register. For. Course() 21
- Slides: 21