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 MagicDraw UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 3
Class: Describes a Set of Objects class name Point visibility attributes - x : int compartment - y : int + getX() : int operations + setX(aX : int) : void + getY() : int compartment operation + setY(aY : int) : void signature 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 / opt visibility opt name multiplicity opt : type opt … Used if the value of the attribute can be derived - (private) only the class can see from other information. this attribute # (protected) only the class and all of its subclasses E.g. <<unique>> + (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 multiplicity opt : type opt = initial-value opt {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 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. questions Quiz Question base class 1..* * association with navigation One possible mapping to Java class Quiz{ class Question { // A list of questions // no reference to Quiz Question [] questions; .... .... } } UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 7
A Class Diagram - Mapping to Java responsible for 1 * Course Person #name : String tech. responsible for 1 -name : String * #imail : String -description : String #homePage : String 1 * * 1 StudentCourseProfile Student -finished : boolean public class Person { protected String name; public class Student extends Person { protected String imail; // protected String homePage; // Navigation // public StudentCourseProfile[] // Navigation studentCourseProfile; protected Course[] responsibleFor; } protected Course[] techResponsibleFor; } 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 Bird Animal. 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 Snake inherits the behaviour move(x,y) specified by the operations of The class Snake realises (implements) Movable (as an interface the interface Movable. Movable has no internal structure). Snake 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. :friendship p1:Person p2:Person f1 * friendship :friendship * Person :friendship f2 :friendship p3:Person p4:Person :friendship possible graph structure, i.e., objects with links UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 12
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? 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. the part aggregation the whole using aggregation allows Company Department a department to be shared * 1..* among companies Composition aggregation (strong aggregation) Company Department 1 1..* Must be 1 or 0..1 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 Department Employee 1 1..* * 1..* a department can only belong an employee can belong to several to one company at a time 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: DirectedAcyclicGraph DirectedTree 0..1 0..1 topRoot * 0..1 * predecessor root Node Node 0..1 child * * successor edge edge UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 17
DirectedAcyclicGraph 0..1 * * predecessor Node * successor :Directed- edge Do you see errors? AcyclicGraph :Node :Node :Node :Node :Node :Node :Node :Node UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 18
DirectedAcyclicGraph 0..1 * * predecessor Node * successor :Directed- edge Do you see errors? AcyclickGraph :Node :Node :Node :Node :Node :Node :Node :Node UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 19
DirectedTree 0..1 topRoot 0..1 root Node 0..1 child * :DirectedTree edge Do you see errors? :Node :Node :Node :Node :Node :Node :Node :Node UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, page no 20
DirectedTree 0..1 topRoot 0..1 1 root Node child * edge :DirectedTree Do you see errors? :Node :Node :Node :Node :Node :Node :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
Recommend
More recommend