UML Class Object Diagram II UML Class Diagram
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 – dependency between classes: Company is dependent on Employee Company Employee add(e : Employee) The operation add has an employee object as argument: A change in Employee may inflict a change of the add operation. UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 2
Dependency on Package Diagram From Magic. Draw UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 3
Class: Describes a Set of Objects class name visibility operation signature Point - x : int - y : int + get. X() : int + set. X(a. X : int) : void + get. Y() : int + set. Y(a. Y : int) : void attributes compartment operations compartment Modelling tool: Rational Rose 2000 Additional compartments may be supplied, e. g. , a constraints compartment. UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 4
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. E. g. <<unique>> - (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 UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 5
Attribute continues Example: Tagged value e. g. Author = Kari … name multiplicityopt : typeopt = initial-valueopt {property-string}opt 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 Questionobjects 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. base class Quiz * questions Question 1. . * association with navigation One possible mapping to Java class Quiz{ // A list of questions Question [] questions; . . } class Question { // no reference to Quiz. . } UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 7
A Class Diagram - Mapping to Java 1 Person responsible for #name : String 1 tech. responsible for #imail : String #home. Page : String * Course : String * -name -description : String 1 * Student 1 public class Person { protected String name; protected String imail; protected String home. Page; // // Navigation protected Course[] responsible. For; protected Course[] tech. Responsible. For; } * Student. Course. Profile -finished : boolean public class Student extends Person { // // Navigation public Student. Course. Profile[] student. Course. Profile; } UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 8
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 A bird is a specialization of an animal. It inherits the structure and behaviour of Animal. Bird Eagle Generalization is a transitive relation! UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 9
Realization: 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) 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). move(x, y) UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 10
Class Diagrams Defines Graph Structures UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 11
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. f 1 p 1: Person * f 2 friendship : friendship p 3: Person : friendship p 2: Person : friendship p 4: Person possible graph structure, i. e. , objects with links UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 12
f 1 * Person * f 2 friendship defines an infinite set of graphs where the nodes are called Person and the edges are called friendship end 1 * Node edge * end 2 “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
Different Types Associations 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
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. aggregation the whole Company * 1. . * the part Department using aggregation allows a department to be shared among companies Composition aggregation (strong aggregation) Company Must be 1 or 0. . 1 1 1. . * Department No limitations on this multiplicity 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 1 1. . * Department a department can only belong to one company at a time * 1. . * Employee an employee can belong to several departments at a time UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 16
• 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: Directed. Acyclic. Graph 0. . 1 * Node Directed. Tree * predecessor successor * edge 0. . 1 top. Root Node root 0. . 1 child * edge UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 17
Directed. Acyclic. Graph 0. . 1 * Node : Directed. Acyclic. Graph : Node successor * Do you see errors? : Node * predecessor edge : Node : Node UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 18
Directed. Acyclic. Graph 0. . 1 * Node : Directed. Acyclick. Graph : Node successor * Do you see errors? : Node * predecessor edge : Node : Node UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 19
Directed. Tree 0. . 1 top. Root Node root 0. . 1 child * : Directed. Tree : Node Do you see errors? : Node edge : Node : Node UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 20
Directed. Tree 0. . 1 top. Root 1 root Node child * : Directed. Tree : Node edge Do you see errors? : Node : Node UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 21
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. ” UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 22
- Slides: 22