#OOP_D_ITS - 8th - Class Diagram

Preview:

Citation preview

11/04/2023Hadziq Fabroyir - Informatics ITS 1

C++ OOP :: Class Diagram

11/04/2023Hadziq Fabroyir - Informatics ITS 2

Classa description of a group of objects with

similar properties, common behavior, and common semantics.

11/04/2023Hadziq Fabroyir - Informatics ITS 3

Classa template for instantiation of objects

Contains:an attribute (state) section and a method (behavior) section

11/04/2023Hadziq Fabroyir - Informatics ITS 4

Attributevisibilityopt <<sterotype>>opt name multiplicityopt : typeopt = initial-valueopt {property-string}opt

Example:Tagged value e.g.Author = Kari

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

Example: email[1..*] :StringIndicating one or more email addresses.If no email is present you will still have a the empty string (””).If email[0..*] : String is specified, the emailcan be null.

11/04/2023Hadziq Fabroyir - Informatics ITS 5

visibilityopt <<sterotype>>opt name(parameter-list) multiplicityopt : return-typeopt

{property-string}opt

Method

Examples:+ <<query>> getX() : double+ setX (newX : double)

11/04/2023Hadziq Fabroyir - Informatics ITS 6

Class Stereotypes

•Manage interactions•Ex: Quiz Scheduler

Control

•Mediate between the system and outside actors •Ex: Quiz Answer

Boundary

•Passive objects•Ex: Quiz Result

Entity

11/04/2023Hadziq Fabroyir - Informatics ITS 7

Robustness Diagram Rules

11/04/2023Hadziq Fabroyir - Informatics ITS 8

The Three Most Important Relationships

In Static Modeling

Generalization

Base sub

Class2Class1

Class2Class1

Association

Dependency

11/04/2023Hadziq Fabroyir - Informatics ITS 9

Generalization

Also called generalization/specialization.

Example: birds are animals, were birds are the most specialized and animals the most general.

11/04/2023Hadziq Fabroyir - Informatics ITS 10

Generalization used in class diagrams

superclass

subclass subclass

generalization arrow

Animal

Bird

11/04/2023Hadziq Fabroyir - Informatics ITS 11

Association

A relationship that describes a set of links between classes of objects, indicating some sort of connection between objects of the involved classes.

Example: student follows a course.

you can distinguish between ordinary association, simple aggregation and composition (strong aggregation).

11/04/2023Hadziq Fabroyir - Informatics ITS 12

Simple Aggregation &

Ordinary AssociationIt seems difficult to give a formal definition of

the distinction between the two concepts.

Ordinary association is used when both of the involved classes are equaly important.

If there is a part-of relation between the involved classes, then aggregation may be adequate. The question of using association or simple aggregation is a conceptual one, it does not say anything about navigation direction and no connection between lifetime is made.

11/04/2023Hadziq Fabroyir - Informatics ITS 13

Association used in Class Diagram

assembly class

aggregation:

part class part class

class 1 class 2

association:

role-1role-2

class 1 class 2

association:

name

name direction

11/04/2023Hadziq Fabroyir - Informatics ITS 14

ExampleUniversity

Faculty

Institute Teacherworks for

11/04/2023Hadziq Fabroyir - Informatics ITS 15

CompositionComposition is a strong type of aggregation indicating that the part object only exist as a part of the assembly class. The part object of an aggregation will be deleted if the assembly object is deleted. An object may be part of only one composite at a time.

assembly class

Composition can be represented in to different ways:

part class

assembly class

part class

11/04/2023Hadziq Fabroyir - Informatics ITS 16

Example

Window

Client Area1

ScrollBar0..2

Component

Menu

0..1

Input Device* *

Keyboard Mouse

11/04/2023Hadziq Fabroyir - Informatics ITS 17

Navigability If you have a Quiz-object, the associated Question-objects can be directly reach from the Quiz-object. You will typically find a reference of each object inside the Quiz-object.

Quiz Question* 1..*

Direction of navigation

ordinary association

class Quiz{ // A list of questions Question [] questions;....}

class Question { // no reference to Quiz....}

11/04/2023Hadziq Fabroyir - Informatics ITS 18

DependencyA dependency relationship indicate that a change in one class may effect the dependent class, but not necessarily the reverse.

You use dependency when you wants to indicate that one thing uses another.

Often used to indicate that a method has object of a class as arguments.

11/04/2023Hadziq Fabroyir - Informatics ITS 19

Example: Dependency

ActionListener ActionEvent

actionPerformed(ActionEvent e)

11/04/2023Hadziq Fabroyir - Informatics ITS 20

MultiplicityThe multiplicity is describing the number of participants (classes) involved in an association. For instance an edge in a graph is connecting exactly two vertexes.

A B1

An A is associatedwith exactly one B

An A is associatedwith one or more B

A B1..*

An A is associatedwith zero or more B

A B*

An A is associatedwith zero or one B

A B0..1

11/04/2023Hadziq Fabroyir - Informatics ITS 21

End of slide show ?

11/04/2023Hadziq Fabroyir - Informatics ITS 22

For your practice …

11/04/2023Hadziq Fabroyir - Informatics ITS 23

Ex: undirected graph

Graph

Vertex Edge2 *

*

1

*

1

11/04/2023Hadziq Fabroyir - Informatics ITS 24

Ex: information system for

schoolSchool

student Course

Department

teachesInstructor

attends

member

has

assignedTo

chairperson0..1

0..1

1..*

1..*

1..*

1..*

*

* *

1 1..*

*

1..*

1..*

11/04/2023Hadziq Fabroyir - Informatics ITS

☺~ Next: <Template> ~☺

[ 25 ]

Recommended