Presentation is loading. Please wait.

Presentation is loading. Please wait.

UML Class & Object Diagram II RELATIONS UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 1.

Similar presentations


Presentation on theme: "UML Class & Object Diagram II RELATIONS UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 1."— Presentation transcript:

1 UML Class & Object Diagram II RELATIONS UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 1

2 Dependency: 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

3 Dependency on Package Diagram From MagicDraw UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 3

4 Ordinary Assocaition With Navigability: If you have a Quiz-object, the associated Question- objects can be directly reach from the Quiz-object. 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.... } QuizQuestion * 1..* One possible mapping to Java association with navigation base class questions UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 4

5 A Class Diagram - Mapping to Java -name : String -description : String #name : String #imail : String #homePage : String Student Course 1 * responsible for Person 1 * tech. responsible for 1 1 StudentCourseProfile -finished : boolean * * public class Person { protected String name; protected String imail; protected String homePage; // // Navigation protected Course[] responsibleFor; protected Course[] techResponsibleFor; } 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; } public class Student extends Person { // // Navigation public StudentCourseProfile[] studentCourseProfile; } UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 5

6 Generalization: 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 6

7 Realization: UML: ”A semantic relationships between classifiers, in which one classifier specifies a contract that another classifier guarantees to carry out”. > 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 7

8 Class Diagrams Defines Graph Structures UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 8

9 Association Describes a set of links between objects, indicating some sort of connection between objects of the involved classes. Example: A person may have friends. Person friendship f1 f2 * * p1:Person p2:Person p3:Personp4:Person :friendship possible graph structure, i.e., objects with links UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 9

10 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 10

11 Different Types Associations In UML class diagrams you can distinguish between: –Ordinary Association –Aggregation –Aggregation (weak aggregation/shared association) –Composition –Composition (strong aggregation) UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 11

12 Aggregation/Composition Indicates that one object contains objects of a given type, i.e., a whole/part relationship. No cycles are allowed. A transitive relation. CompanyDepartment 1 1..* Composition aggregation (strong aggregation) CompanyDepartment * 1..* aggregation using aggregation allows a department to be shared among companies Must be 1 or 0..1No limitations on this multiplicity the whole the part UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 12

13 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. CompanyDepartment 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 13

14 Composition defines a directed tree and an aggregation defines a directed graph (without cycles). Using these properties to define a directed graph and directed tree: Node child * root 0..1 DirectedTree 0..1 Node * * DirectedAcyclicGraph 0..1 * edge predecessor successor topRoot UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 14

15 :Node :Directed- AcyclicGraph :Node Do you see errors? Node * * DirectedAcyclicGraph 0..1 * edge predecessor successor UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 15

16 :Node :Directed- AcyclickGraph :Node Do you see errors? Node * * DirectedAcyclicGraph 0..1 * edge predecessor successor UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 16

17 :Node :DirectedTree :Node Do you see errors? Node child * root 0..1 DirectedTree 0..1 edge topRoot UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 17

18 :Node :DirectedTree :Node Do you see errors? Node child * root 1 DirectedTree 0..1 edge topRoot UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 18

19 UML 2.1 specification: “… If a composite is deleted, all of its parts are normally deleted with it… deleting an element in one part of the graph will also result in the deletion of all elements of the subgraph below that element.” Deletion Characteristics UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 19


Download ppt "UML Class & Object Diagram II RELATIONS UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 1."

Similar presentations


Ads by Google