UML Class & Object Diagram
II
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 1
II UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, - - PowerPoint PPT Presentation
UML Class & Object Diagram II UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 1 Dependency: A relationship between two modeling elements indicates that a change in the destination may effect the source. Example
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 1
A relationship between two modeling elements indicates that a change in the destination may effect the source.
Employee Company
add(e : Employee)
The operation add has an employee object as argument: A change in Employee may inflict a change of the add operation.
Example – dependency between classes: Company is dependent on Employee
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 2
From MagicDraw
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 3
Point
+ getX() : int + setX(aX : int) : void + getY() : int + setY(aY : int) : void
Additional compartments may be supplied, e.g., a constraints compartment.
Modelling tool: Rational Rose 2000
class name
attributes compartment
compartment visibility
signature
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 4
(Implemented as Field in Java, data member in C++)
Description of a named slot of a specified type in a class. Each object of the class separately holds a value of the type.
<<stereotype>>opt / optvisibilityopt name multiplicityopt : typeopt …
E.g. <<unique>>
this attribute # (protected) only the class and all of its subclasses + (public) all classes that can see the class can also see the attribute ~ (package) only classes in the package can see the attribute Used if the value of the attribute can be derived from other information.
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 5
… name multiplicityopt : typeopt = initial-valueopt {property-string}opt
Example: Tagged value e.g. Author = Kari
Example: email[1..*] : String Indicating one or more email addresses. (If no email is present you will still have the empty string (””).) If email[0..*] : String is specified, then email can be null.
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 6
Ordinary Assocaition With Navigability:
If you have a Quiz-object, the associated Question-
I.e., there will be a reference to each Question-object inside the Quiz-object but not the other way around.
class Quiz{ // A list of questions Question [] questions; .... } class Question { // no reference to Quiz .... }
Quiz Question * 1..* One possible mapping to Java
association with navigation base class
questions
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 7
#name : String #imail : String #homePage : String
Student Course
1
*
responsible for
Person
1
*
1 1
StudentCourseProfile
*
*
public class Person { protected String name; protected String imail; protected String homePage; // // Navigation protected Course[] responsibleFor; protected Course[] techResponsibleFor; } public class Student extends Person { // // Navigation public StudentCourseProfile[] studentCourseProfile; }
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 8
A relationship between a more general element and a more specific one. For example: A bird is also an animal.
(Generalization is not an association, but it do relate objects in regard to classification.) Animal Bird
A bird is a specialization of an animal. It inherits the structure and behaviour of Animal. Generalization is a transitive relation!
Eagle
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 9
UML: ”A semantic relationships between classifiers, in which one classifier specifies a contract that another classifier guarantees to carry out”.
<<interface>>
Movable
move(x,y)
Snake
move(x,y)
The class Snake realises (implements) the interface Movable. Snake inherits the behaviour specified by the operations of Movable (as an interface Movable has no internal structure).
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 10
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 11
indicating some sort of connection between
Person
friendship f1 f2 * *
p1:Person p2:Person p3:Person p4:Person
:friendship :friendship :friendship :friendship :friendship
possible graph structure, i.e., objects with links
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 12
Person
friendship f1 f2 * *
defines an infinite set of graphs where the nodes are called Person and the edges are called friendship Node
edge end1 end2 * *
“ordinary graph” with “ordinary names” What if we need to attach some information to the edges?
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 13
In UML class diagrams you can distinguish between:
– Ordinary Association – Aggregation
(weak aggregation/shared association)
– Composition
(strong aggregation)
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 14
i.e., a whole/part relationship.
Company Department 1 1..*
Composition aggregation (strong aggregation)
Company Department * 1..*
aggregation using aggregation allows a department to be shared among companies Must be 1 or 0..1 No limitations on this multiplicity the whole the part
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 15
Aggregation is a weaker form of aggregation than composition. A part instance might be included in more than one aggregation at a time, which is not allowed for composition.
Company Department 1 1..* Employee * 1..*
a department can only belong to one company at a time an employee can belong to several departments at a time
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 16
aggregation defines a directed graph (without cycles).
directed tree:
Node
child * root 0..1
DirectedTree
0..1 0..1
Node
* *
DirectedAcyclicGraph
0..1 * edge edge predecessor successor topRoot
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 17
:Node :Node :Node :Node :Node :Directed- AcyclicGraph :Node :Node :Node
Do you see errors?
Node
* *
DirectedAcyclicGraph
0..1 * edge predecessor successor
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 18
:Node :Node :Node :Node :Node :Directed- AcyclickGraph :Node :Node :Node
Do you see errors?
Node
* *
DirectedAcyclicGraph
0..1 * edge predecessor successor
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 19
:Node :Node :Node :Node :Node :DirectedTree :Node :Node :Node
Do you see errors?
Node
child * root 0..1
DirectedTree
0..1 0..1 edge topRoot
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 20
:Node :Node :Node :Node :Node :DirectedTree :Node :Node :Node
Do you see errors?
Node
child * root 1
DirectedTree
0..1 0..1 edge topRoot
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 21
UML 2.1 specification: “… If a composite is deleted, all of its parts are normally deleted with it… deleting an element in
UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 22