Presentation is loading. Please wait.

Presentation is loading. Please wait.

UML Class & Object Diagram II

Similar presentations


Presentation on theme: "UML Class & Object Diagram II"— Presentation transcript:

1 UML Class & Object Diagram II

2 Dependency: A relationship between two modeling elements indicates that a change in the destination may effect the source. Example – dependency between classes: Company is dependent on Employee Company add(e : Employee) Employee The operation add has an employee object as argument: A change in Employee may inflict a change of the add operation.

3 Dependency on Package Diagram
From MagicDraw

4 Class: Describes a Set of Objects
class name attributes compartment operations compartment visibility operation signature Point - x : int - y : int + getX() : int + setX(aX : int) : void + getY() : int + setY(aY : int) : void Modelling tool: Rational Rose 2000 Coming slides will say more about visibility… Additional compartments may be supplied, e.g., a constraints compartment.

5 Attribute/Property (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 … Used if the value of the attribute can be derived from other information. - (private) only the class can see 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 E.g. <<unique>> Example: Circle: attribute radius, circumference can de derived (2 x pi x radius) position: x, y with default values 0

6 Attribute continues Example: Tagged value e.g. Author = Kari … name multiplicityopt : typeopt = initial-valueopt {property-string}opt Example: [1..*] : String Indicating one or more addresses. (If no is present you will still have the empty string (””).) If [0..*] : String is specified, then can be null. Example: Circle: attribute radius, circumference can de derived (2 x pi x radius) position: x, y with default values 0

7 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. Quiz questions Question base class * 1..* association with navigation One possible mapping to Java class Quiz{ // A list of questions Question [] questions; .... } class Question { // no reference to Quiz .... }

8 A Class Diagram - Mapping to Java
1 responsible for * Course Person -name : String -description : String #name : String #imail : String #homePage : String 1 tech. responsible for * 1 * * 1 StudentCourseProfile Student -finished : boolean 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; }

9 Generalization: Eagle
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 A bird is a specialization of an animal. It inherits the structure and behaviour of Animal. Bird Eagle Generalization is a transitive relation!

10 Realization: UML: ”A semantic relationships between classifiers, in which one classifier specifies a contract that another classifier guarantees to carry out”. <<interface>> Movable Snake inherits the behaviour specified by the operations of Movable (as an interface Movable has no internal structure). move(x,y) Snake move(x,y) The class Snake realises (implements) the interface Movable.

11 Class Diagrams Defines Graph Structures

12 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. :friendship p1:Person p2:Person f1 * friendship Person * :friendship :friendship f2 :friendship p3:Person p4:Person :friendship possible graph structure, i.e., objects with links

13 “ordinary graph” with “ordinary names”
f1 * friendship Person * f2 defines an infinite set of graphs where the nodes are called Person and the edges are called friendship end1 edge * * Node end2 “ordinary graph” with “ordinary names” What if we need to attach some information to the edges?

14 Different Types Associations
In UML class diagrams you can distinguish between: Ordinary Association Aggregation (weak aggregation/shared association) Composition (strong aggregation)

15 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. the part the whole aggregation using aggregation allows a department to be shared among companies Company Department * 1..* Composition aggregation (strong aggregation) Company Department 1 1..* Must be 1 or 0..1 No limitations on this multiplicity

16 Aggregation is a weaker form of aggregation than composition
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 Employee 1 1..* * 1..* a department can only belong to one company at a time an employee can belong to several departments at a time

17 DirectedAcyclicGraph
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: DirectedAcyclicGraph DirectedTree 0..1 0..1 * 0..1 topRoot * predecessor root Node Node 0..1 successor  * child * edge edge

18 Do you see errors? DirectedAcyclicGraph Node :Directed- AcyclicGraph
0..1 * * predecessor Node successor  * :Directed- AcyclicGraph edge Do you see errors? :Node :Node :Node :Node :Node :Node :Node :Node

19 Do you see errors? DirectedAcyclicGraph Node :Directed- AcyclickGraph
0..1 * * predecessor Node successor  * :Directed- AcyclickGraph edge Do you see errors? :Node :Node :Node :Node :Node :Node :Node :Node

20 Do you see errors? DirectedTree Node :DirectedTree :Node :Node :Node
0..1 0..1 topRoot root Node 0..1 child * :DirectedTree Do you see errors? edge :Node :Node :Node :Node :Node :Node :Node :Node

21 Do you see errors? DirectedTree Node :DirectedTree :Node :Node :Node
0..1 0..1 topRoot 1 root Node child * edge :DirectedTree Do you see errors? :Node :Node :Node :Node :Node :Node :Node :Node

22 Deletion Characteristics
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.”


Download ppt "UML Class & Object Diagram II"

Similar presentations


Ads by Google