Session13-Class Diagram (1).pdf

39 views 42 slides Nov 18, 2022
Slide 1
Slide 1 of 42
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42

About This Presentation

adf


Slide Content

Session 13: Class Diagram
R2S Academy –Internal Use –Author: TUAN NGO

Table of Content
Class Diagram -Definition
Examples
Practice & Exercises
R2S Academy –Internal Use –Author: TUAN NGO
1
2
3
Objectives

Definition
Class Diagram

Class Diagram
Definition

Class vs Object
üA Class is a blueprint for an object. Objects and classes go
hand in hand.
üWe use classes to create objects. So a class describes what an
object will be, but it isn't the object itself.
üClasses describe the type of objects, while objects are usable
instances of classes. Each Object was built from the same set
of blueprints and therefore contains the same components
(properties and methods)
Class Diagram
Definition

What is Class diagram?
üClass diagram is a graphical notation used to construct and
visualize object oriented systems. A class diagram describes
the structure of a system by showing the system's
§classes
§their attributes
§operations (or methods)
§and the relationships among objects
üClass diagram is not only used for visualizing, describing, and
documenting different aspects of a system but also for
constructing executable code of the software application
Class Diagram
Definition

Use of Class diagram?
üDescribing the static view of the system
üShowing the collaboration among the elements of the static view
üDescribing the functionalities performed by the system
üConstruction of software applications using object oriented
languages. Class diagrams are the only diagrams which can be
directly mapped with object-oriented languages and thus widely
used at the time of construction →the most popular UML
diagram in the coder community
Class Diagram
Definition

Elements
Class Diagram

Class Diagram
Elements
1. Main components of a Class2. Relationships

Class Diagram
Elements
1.VitalcomponentsofaClass
1.1.UpperSection
1.2.MiddleSection
1.3.LowerSection
2.Relationships

Class Diagram
Elements
1.VitalcomponentsofaClass
1.1.UpperSection:nameoftheclass
üCapitalizetheinitialletteroftheclassname
üPlacetheclassnameinthecenteroftheuppersection
üAclassnamemustbewritteninboldformat
1.2.MiddleSection
1.3.LowerSection
2.Relationships

Class Diagram
Elements
1. Vital components of a Class
1.1. Upper Section
1.2. Middle Section: class attributes, with following characteristics:
üA meaningful name assigned to the attribute, explain its usage
üThe accessibility of an attribute class is illustrated by the visibility factors
üThe attributes are written along with its visibility factors, which are:
public (+) | private (-) | protected (#) | and package (~)
1.3. Lower Section
2. Relationships

Class Diagram
Elements
1. Vital components of a Class
1.1. Upper Section
1.2. Middle Section: class attributes, with following characteristics:
1.3. Lower Section
2. Relationships

Class Diagram
Elements
1.VitalcomponentsofaClass
1.1.UpperSection
1.2.MiddleSection
1.3. Lower Section:methods or operations. It demonstrates how a class
interacts with data. Each attribute has a type. Each operation has a signature
2.Relationships

Class Diagram
Elements
1.VitalcomponentsofaClass
1.1.UpperSection
1.2.MiddleSection
1.3. Lower Section:Signatures (Data types)
2.Relationships

Class Diagram
Elements
1.VitalcomponentsofaClass
2.Relationships
2.1.Association(Kếthợp)
2.2.Dependency(Phụthuộc)
2.3.Generalization/Inheritance(Kếthừa)
2.4.Realization(Hiệnthựchóa)

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.1. Association (kếthợp)
üA structural link between two peer classes
üThere is an association between Class1 and Class2
üA solid line connecting two classes
üIt can form several types of associations: one-to-one, one-to-many, many-to-one
and many-to-many
üMultiplicity: A multiplicity is a factor associated with an attribute. It specifies
how many instances of attributes are created when a class is initialized. If a
multiplicity is not specified, by default oneis considered as a default multiplicity

Class diagram
Elements
1.VitalcomponentsofaClass
2.Relationships
2.1.Association-Examples

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.1. Association
4 types of association
üunidirectional/ directed (mộtchiều)
übi-directional (haichiều)
üreflexive (phảnxạ)
üaggregation (tậphợp)
The mostly used associations are unidirectional and bi-directional.

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.1. Association ←Unidirectional/ directed
üThe directed association is related to the direction of flow
within association classes
üIn a directed association, the flow is directed. The
association from one class to another class flows in a single
direction only
It is denoted using a solid line with an arrowhead

Class diagram
Elements
1.VitalcomponentsofaClass
2.Relationships
2.1. Association ←Bi-directional
Two objects might store each other in fields

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.1. Association ←Reflexive
üIn a reflexive association, the instances of the
same class can be related to each other
üReflexive association states that a link or a
connection can be present within the objects of
the same class
üThis occurs when a class may have multiple
functions or responsibilities

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.1. Association ←Aggregation (has-a relationship)
üIt represents a "part of" relationship
üClass2 is part of Class1 (collection)
üMany instances (denoted by the *) of Class2 can be
associated with Class1
üObjects of Class1 and Class2 have separate lifetimes

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.1. Association ←Aggregation ←Composition(part-of
relationship)
üA special type of aggregation where parts are
destroyed when the whole is destroyed
üObjects of Class2 live and die with Class1
üClass2 cannot stand by itself

Class diagram
Elements
Aggregation relationshipComposition relationship
DependencyIn an aggregation relationship, a child can exist
independent of a parent
In a composition relationship, the child cannot
exist independent of the parent
Type of RelationshipHas-a relationshipPart-of relationship
Type of Associationa weak associationstrong association
ExamplesA doctor has patients when the doctor gets
transfer to another hospital, the patients do not
accompany to a new workplace
A hospital and its wards. If the hospital is
destroyed, the wards also get destroyed
1.VitalcomponentsofaClass
2.Relationships
2.1.Association←Aggregation←Composition

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.2. Dependency
üA special type of association
üExists between two classes if changes to the definition
of one may cause changes to the other (but not the
other way around)
üClass1 depends on Class2

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.3. Generalization/ Inheritance
üRepresents an "is-a” / parent-child relationship
üSubClass1 and SubClass2 are specializations of SuperClass
(Abstract Class)

Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.4. Realization (hiệnthựchóa)
üOne entity denotes some responsibility which is not
implemented by itself and the other entity that
implements them.
üThis relationship is mostly found in the case of interfaces

1. Vital components of a Class
2. Relationships
üExercise: Develop mind-map diagram for
Class Diagram Relationships
Class Diagram
Elements

1.VitalcomponentsofaClass
2.Relationships
Class Diagram
Elements

vs Use Case Diagram
Class Diagram

Class diagram
Use case diagram vs Class diagram

Use Case Diagram
Notations / Symbols
Relationships
üAssociation: A line between actors and use cases represents
which actors are associated with which use cases
üInclude: defines that a use case contains the behavior
defined in another use case
üExtend: specifies that the behavior of a use case may be
extended by the behavior of another use case
üGeneralization: represent inheritance relationship between
model elements of same type
AssociationIncludeExtendGeneralization

Use case diagramClass diagram
What kind of?Behavioral diagramStructural diagram
What describe?Describes functional requirementsDescribes the structure of a system
How to describe?
By mentioning that who will perform what function and
which kind of association is exist between functions (use
cases)
By showing the system’s classes, their attributes,
functions and the relationships among objects
Supported
relationshipsAssociation, includes, extends, GeneralizationAssociation, Dependency, Generalization, Realization
SpecifySpecify the behavior (what system will do?)Specify the internal structure that will help to complete
a functionality mentioned in use cases
RepresentationUse cases can be denoted both by textual (UC
description) and visual representation (UC diagram)Only denoted by visual representation
What summarizes?Only summarizes relationships between use cases,
actors, and system
Only summarizes relationships between classes of the
system
Order of executionDoes not show the order in which steps are performed
to achieve the goals of each use caseDoes not show the order in which classes executes

Examples
Class Diagram

Class Diagram
Example 1 –Order System

Class Diagram
Example 2
Generalization/ Inheritance

Class Diagram
Example 3
üGeneralization/ Inheritance
üRealization

Class Diagram
Example 4 -Package

Practice
Class Diagram

Session 13 Review
Class Diagram

Class Diagram
Session Review
Review content
1.What is multiplicity in Class diagram?
2.What is Reflexiveassociation in Class diagram?
3.Aggregationrelationship vsCompositionrelationship?
4.Use Casediagram vsClassdiagram?
5.Mind-map diagram: develop a mind-map diagram to present all of Class diagram relationships types