II UML Class Diagram & Object Diagram II, Jan Pettersen Nytun, - - PowerPoint PPT Presentation

ii
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

UML Class & Object Diagram

II

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

slide-2
SLIDE 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

slide-3
SLIDE 3

Dependency on Package Diagram

From MagicDraw

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

slide-4
SLIDE 4

Point

  • x : int
  • y : int

+ getX() : int + setX(aX : int) : void + getY() : int + setY(aY : int) : void

Class: Describes a Set of Objects

Additional compartments may be supplied, e.g., a constraints compartment.

Modelling tool: Rational Rose 2000

class name

attributes compartment

  • perations

compartment visibility

  • peration

signature

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

slide-5
SLIDE 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 …

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

slide-6
SLIDE 6

Attribute continues

… 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

slide-7
SLIDE 7

Ordinary Assocaition With Navigability:

If you have a Quiz-object, the associated Question-

  • bjects 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 .... }

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

slide-8
SLIDE 8

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 Student extends Person { // // Navigation public StudentCourseProfile[] studentCourseProfile; }

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

slide-9
SLIDE 9

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 9

slide-10
SLIDE 10

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)

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

slide-11
SLIDE 11

Class Diagrams Defines Graph Structures

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

slide-12
SLIDE 12

Association

  • Describes a set of links between objects,

indicating some sort of connection between

  • bjects of the involved classes.
  • Example: A person may have friends.

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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

slide-15
SLIDE 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.

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

slide-16
SLIDE 16

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

slide-17
SLIDE 17
  • 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 0..1

Node

* *

DirectedAcyclicGraph

0..1 * edge edge predecessor successor topRoot

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

slide-18
SLIDE 18

: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

slide-19
SLIDE 19

: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

slide-20
SLIDE 20

: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

slide-21
SLIDE 21

: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

slide-22
SLIDE 22

UML 2.1 specification: “… If a composite is deleted, all of its parts are normally deleted with it… deleting an element in

  • ne part of the graph will also result in the deletion
  • f all elements of the subgraph below that element.”

Deletion Characteristics

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