SlideShare a Scribd company logo
1 of 42
Download to read offline
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 Class 2. Relationships
Class Diagram
Elements
1. Vital components of a Class
1.1. Upper Section
1.2. Middle Section
1.3. Lower Section
2. Relationships
Class Diagram
Elements
1. Vital components of a Class
1.1. Upper Section: name of the class
ü Capitalize the initial letter of the class name
ü Place the class name in the center of the upper section
ü A class name must be written in bold format
1.2. Middle Section
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:
ü 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. Vital components of a Class
1.1. Upper Section
1.2. Middle Section
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. Vital components of a Class
1.1. Upper Section
1.2. Middle Section
1.3. Lower Section: Signatures (Data types)
2. Relationships
Class Diagram
Elements
1. Vital components of a Class
2. Relationships
2.1. Association (Kết hợp)
2.2. Dependency (Phụ thuộc)
2.3. Generalization/ Inheritance (Kế thừa)
2.4. Realization (Hiện thực hóa)
Class diagram
Elements
1. Vital components of a Class
2. Relationships
2.1. Association (kết hợ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 one is considered as a default multiplicity
Class diagram
Elements
1. Vital components of a Class
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ột chiều)
ü bi-directional (hai chiều)
ü reflexive (phản xạ)
ü aggregation (tập hợ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. Vital components of a Class
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 relationship Composition relationship
Dependency In 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 Relationship Has-a relationship Part-of relationship
Type of Association a weak association strong association
Examples A 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. Vital components of a Class
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ện thực hó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. Vital components of a Class
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
Association Include Extend Generalization
Use case diagram Class diagram
What kind of? Behavioral diagram Structural diagram
What describe? Describes functional requirements Describes 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
relationships
Association, includes, extends, Generalization Association, Dependency, Generalization, Realization
Specify Specify the behavior (what system will do?)
Specify the internal structure that will help to complete
a functionality mentioned in use cases
Representation
Use 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 execution
Does not show the order in which steps are performed
to achieve the goals of each use case
Does 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 Reflexive association in Class diagram?
3. Aggregation relationship vs Composition relationship?
4. Use Case diagram vs Class diagram?
5. Mind-map diagram: develop a mind-map diagram to present all of Class diagram relationships types

More Related Content

Similar to Here are the answers to the review questions:1. 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 one is considered as a default multiplicity. 2. In a reflexive association, the instances of the same class can be related to each other. It states that a link or connection can be present within the objects of the same class. 3. Aggregation represents a weak "has-a" relationship where the child can exist independently of the parent. Composition represents a strong "part-of" relationship where the child cannot exist without the parent.4. Use case diagram describes

Unit 2(advanced class modeling & state diagram)
Unit  2(advanced class modeling & state diagram)Unit  2(advanced class modeling & state diagram)
Unit 2(advanced class modeling & state diagram)Manoj Reddy
 
Advantages and disadvantages of er model in DBMS. Types of database models ..
Advantages and disadvantages of er model in DBMS. Types of database models ..Advantages and disadvantages of er model in DBMS. Types of database models ..
Advantages and disadvantages of er model in DBMS. Types of database models ..Nimrakhan89
 
5e7ry754.pptx
5e7ry754.pptx5e7ry754.pptx
5e7ry754.pptxqwert001
 
Lecture#02, building blocks of uml ASE
Lecture#02, building blocks of uml ASELecture#02, building blocks of uml ASE
Lecture#02, building blocks of uml ASEbabak danyal
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UMLyndaravind
 
08 class and sequence diagrams
08   class and sequence diagrams08   class and sequence diagrams
08 class and sequence diagramskebsterz
 
Intro to UML 2
Intro to UML 2Intro to UML 2
Intro to UML 2rchakra
 
2012.10 - DDI Lifecycle - Moving Forward - 3
2012.10 - DDI Lifecycle - Moving Forward - 32012.10 - DDI Lifecycle - Moving Forward - 3
2012.10 - DDI Lifecycle - Moving Forward - 3Dr.-Ing. Thomas Hartmann
 
Different Types Diagrams
Different Types Diagrams  Different Types Diagrams
Different Types Diagrams ShauryaGupta38
 
Sree Dattha Institute of Engineering and Science
Sree Dattha Institute of Engineering and ScienceSree Dattha Institute of Engineering and Science
Sree Dattha Institute of Engineering and Sciencedrprkr74
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UMLSwatiS-BA
 
UML Training for Business Analysts
UML Training for Business AnalystsUML Training for Business Analysts
UML Training for Business AnalystsSwatiS-BA
 
UML, ER and Dimensional Modelling
UML, ER and Dimensional ModellingUML, ER and Dimensional Modelling
UML, ER and Dimensional ModellingStefano Dalla Palma
 
class Diagram.ppt
class Diagram.pptclass Diagram.ppt
class Diagram.pptusama537223
 

Similar to Here are the answers to the review questions:1. 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 one is considered as a default multiplicity. 2. In a reflexive association, the instances of the same class can be related to each other. It states that a link or connection can be present within the objects of the same class. 3. Aggregation represents a weak "has-a" relationship where the child can exist independently of the parent. Composition represents a strong "part-of" relationship where the child cannot exist without the parent.4. Use case diagram describes (20)

Css uml
Css umlCss uml
Css uml
 
Unit 2(advanced class modeling & state diagram)
Unit  2(advanced class modeling & state diagram)Unit  2(advanced class modeling & state diagram)
Unit 2(advanced class modeling & state diagram)
 
Advantages and disadvantages of er model in DBMS. Types of database models ..
Advantages and disadvantages of er model in DBMS. Types of database models ..Advantages and disadvantages of er model in DBMS. Types of database models ..
Advantages and disadvantages of er model in DBMS. Types of database models ..
 
5e7ry754.pptx
5e7ry754.pptx5e7ry754.pptx
5e7ry754.pptx
 
Lecture#02, building blocks of uml ASE
Lecture#02, building blocks of uml ASELecture#02, building blocks of uml ASE
Lecture#02, building blocks of uml ASE
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
08 class and sequence diagrams
08   class and sequence diagrams08   class and sequence diagrams
08 class and sequence diagrams
 
Software Testing and UML Lab
Software Testing and UML LabSoftware Testing and UML Lab
Software Testing and UML Lab
 
Intro to UML 2
Intro to UML 2Intro to UML 2
Intro to UML 2
 
2012.10 - DDI Lifecycle - Moving Forward - 3
2012.10 - DDI Lifecycle - Moving Forward - 32012.10 - DDI Lifecycle - Moving Forward - 3
2012.10 - DDI Lifecycle - Moving Forward - 3
 
Different Types Diagrams
Different Types Diagrams  Different Types Diagrams
Different Types Diagrams
 
Sree Dattha Institute of Engineering and Science
Sree Dattha Institute of Engineering and ScienceSree Dattha Institute of Engineering and Science
Sree Dattha Institute of Engineering and Science
 
UNIT II DBMS.pptx
UNIT II DBMS.pptxUNIT II DBMS.pptx
UNIT II DBMS.pptx
 
Class diagram
Class diagramClass diagram
Class diagram
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
UML Training for Business Analysts
UML Training for Business AnalystsUML Training for Business Analysts
UML Training for Business Analysts
 
OOSE UNIT-2.pdf
OOSE UNIT-2.pdfOOSE UNIT-2.pdf
OOSE UNIT-2.pdf
 
UML, ER and Dimensional Modelling
UML, ER and Dimensional ModellingUML, ER and Dimensional Modelling
UML, ER and Dimensional Modelling
 
classdiagram.pptx
classdiagram.pptxclassdiagram.pptx
classdiagram.pptx
 
class Diagram.ppt
class Diagram.pptclass Diagram.ppt
class Diagram.ppt
 

More from PeterTran514407

Session17-Software Testing.pdf
Session17-Software Testing.pdfSession17-Software Testing.pdf
Session17-Software Testing.pdfPeterTran514407
 
Session03-Requirement (1).pdf
Session03-Requirement (1).pdfSession03-Requirement (1).pdf
Session03-Requirement (1).pdfPeterTran514407
 
Session15+16-User Story (2).pdf
Session15+16-User Story (2).pdfSession15+16-User Story (2).pdf
Session15+16-User Story (2).pdfPeterTran514407
 
Session01-BA Introduction.pdf
Session01-BA Introduction.pdfSession01-BA Introduction.pdf
Session01-BA Introduction.pdfPeterTran514407
 

More from PeterTran514407 (6)

Session17-Software Testing.pdf
Session17-Software Testing.pdfSession17-Software Testing.pdf
Session17-Software Testing.pdf
 
Session07-Diagram.pdf
Session07-Diagram.pdfSession07-Diagram.pdf
Session07-Diagram.pdf
 
Session03-Requirement (1).pdf
Session03-Requirement (1).pdfSession03-Requirement (1).pdf
Session03-Requirement (1).pdf
 
bdd-190104042740.pdf
bdd-190104042740.pdfbdd-190104042740.pdf
bdd-190104042740.pdf
 
Session15+16-User Story (2).pdf
Session15+16-User Story (2).pdfSession15+16-User Story (2).pdf
Session15+16-User Story (2).pdf
 
Session01-BA Introduction.pdf
Session01-BA Introduction.pdfSession01-BA Introduction.pdf
Session01-BA Introduction.pdf
 

Recently uploaded

Town of Haverhill's Statement of Facts for Summary Judgment on Counterclaims ...
Town of Haverhill's Statement of Facts for Summary Judgment on Counterclaims ...Town of Haverhill's Statement of Facts for Summary Judgment on Counterclaims ...
Town of Haverhill's Statement of Facts for Summary Judgment on Counterclaims ...Rich Bergeron
 
Choosing the Right Business Structure for Your Small Business in Texas
Choosing the Right Business Structure for Your Small Business in TexasChoosing the Right Business Structure for Your Small Business in Texas
Choosing the Right Business Structure for Your Small Business in TexasBrandy Austin
 
Are There Any Alternatives To Jail Time For Sex Crime Convictions in Los Angeles
Are There Any Alternatives To Jail Time For Sex Crime Convictions in Los AngelesAre There Any Alternatives To Jail Time For Sex Crime Convictions in Los Angeles
Are There Any Alternatives To Jail Time For Sex Crime Convictions in Los AngelesChesley Lawyer
 
Power Point Obligations and contracts Article 1313-1327
Power Point Obligations and contracts Article 1313-1327Power Point Obligations and contracts Article 1313-1327
Power Point Obligations and contracts Article 1313-1327bariajenne
 
OMassmann - Investment into the grid and transmission system in Vietnam (2024...
OMassmann - Investment into the grid and transmission system in Vietnam (2024...OMassmann - Investment into the grid and transmission system in Vietnam (2024...
OMassmann - Investment into the grid and transmission system in Vietnam (2024...Dr. Oliver Massmann
 
Ashutosh Yadav v. State of UP 22nd March, 2024 All HC.pdf
Ashutosh Yadav v. State of UP 22nd March, 2024 All HC.pdfAshutosh Yadav v. State of UP 22nd March, 2024 All HC.pdf
Ashutosh Yadav v. State of UP 22nd March, 2024 All HC.pdfVidit Agrawal
 
Illinois Department Of Corrections reentry guide
Illinois Department Of Corrections reentry guideIllinois Department Of Corrections reentry guide
Illinois Department Of Corrections reentry guideillinoisworknet11
 
Town of Haverhill's Motion for Summary Judgment on DTC Counterclaims
Town of Haverhill's Motion for Summary Judgment on DTC CounterclaimsTown of Haverhill's Motion for Summary Judgment on DTC Counterclaims
Town of Haverhill's Motion for Summary Judgment on DTC CounterclaimsRich Bergeron
 
Right to life and personal liberty under article 21
Right to life and personal liberty under article 21Right to life and personal liberty under article 21
Right to life and personal liberty under article 21vasanthakumarsk17
 
Town of Haverhill's Statement of Material Facts For Declaratory Judgment Moti...
Town of Haverhill's Statement of Material Facts For Declaratory Judgment Moti...Town of Haverhill's Statement of Material Facts For Declaratory Judgment Moti...
Town of Haverhill's Statement of Material Facts For Declaratory Judgment Moti...Rich Bergeron
 
ENG7-Q4-MOD3. determine the worth of ideas mentioned in the text listened to
ENG7-Q4-MOD3. determine the worth of ideas mentioned in the text listened toENG7-Q4-MOD3. determine the worth of ideas mentioned in the text listened to
ENG7-Q4-MOD3. determine the worth of ideas mentioned in the text listened toirenelavilla52178
 
Hungarian legislation made by Robert Miklos
Hungarian legislation made by Robert MiklosHungarian legislation made by Robert Miklos
Hungarian legislation made by Robert Miklosbeduinpower135
 
Town of Haverhill's Summary Judgment Motion for Declaratory Judgment Case
Town of Haverhill's Summary Judgment Motion for Declaratory Judgment CaseTown of Haverhill's Summary Judgment Motion for Declaratory Judgment Case
Town of Haverhill's Summary Judgment Motion for Declaratory Judgment CaseRich Bergeron
 
RA. 7432 and RA 9994 Senior Citizen .pptx
RA. 7432 and RA 9994 Senior Citizen .pptxRA. 7432 and RA 9994 Senior Citizen .pptx
RA. 7432 and RA 9994 Senior Citizen .pptxJFSB1
 
1990-2004 Bar Questions and Answers in Sales
1990-2004 Bar Questions and Answers in Sales1990-2004 Bar Questions and Answers in Sales
1990-2004 Bar Questions and Answers in SalesMelvinPernez2
 

Recently uploaded (15)

Town of Haverhill's Statement of Facts for Summary Judgment on Counterclaims ...
Town of Haverhill's Statement of Facts for Summary Judgment on Counterclaims ...Town of Haverhill's Statement of Facts for Summary Judgment on Counterclaims ...
Town of Haverhill's Statement of Facts for Summary Judgment on Counterclaims ...
 
Choosing the Right Business Structure for Your Small Business in Texas
Choosing the Right Business Structure for Your Small Business in TexasChoosing the Right Business Structure for Your Small Business in Texas
Choosing the Right Business Structure for Your Small Business in Texas
 
Are There Any Alternatives To Jail Time For Sex Crime Convictions in Los Angeles
Are There Any Alternatives To Jail Time For Sex Crime Convictions in Los AngelesAre There Any Alternatives To Jail Time For Sex Crime Convictions in Los Angeles
Are There Any Alternatives To Jail Time For Sex Crime Convictions in Los Angeles
 
Power Point Obligations and contracts Article 1313-1327
Power Point Obligations and contracts Article 1313-1327Power Point Obligations and contracts Article 1313-1327
Power Point Obligations and contracts Article 1313-1327
 
OMassmann - Investment into the grid and transmission system in Vietnam (2024...
OMassmann - Investment into the grid and transmission system in Vietnam (2024...OMassmann - Investment into the grid and transmission system in Vietnam (2024...
OMassmann - Investment into the grid and transmission system in Vietnam (2024...
 
Ashutosh Yadav v. State of UP 22nd March, 2024 All HC.pdf
Ashutosh Yadav v. State of UP 22nd March, 2024 All HC.pdfAshutosh Yadav v. State of UP 22nd March, 2024 All HC.pdf
Ashutosh Yadav v. State of UP 22nd March, 2024 All HC.pdf
 
Illinois Department Of Corrections reentry guide
Illinois Department Of Corrections reentry guideIllinois Department Of Corrections reentry guide
Illinois Department Of Corrections reentry guide
 
Town of Haverhill's Motion for Summary Judgment on DTC Counterclaims
Town of Haverhill's Motion for Summary Judgment on DTC CounterclaimsTown of Haverhill's Motion for Summary Judgment on DTC Counterclaims
Town of Haverhill's Motion for Summary Judgment on DTC Counterclaims
 
Right to life and personal liberty under article 21
Right to life and personal liberty under article 21Right to life and personal liberty under article 21
Right to life and personal liberty under article 21
 
Town of Haverhill's Statement of Material Facts For Declaratory Judgment Moti...
Town of Haverhill's Statement of Material Facts For Declaratory Judgment Moti...Town of Haverhill's Statement of Material Facts For Declaratory Judgment Moti...
Town of Haverhill's Statement of Material Facts For Declaratory Judgment Moti...
 
ENG7-Q4-MOD3. determine the worth of ideas mentioned in the text listened to
ENG7-Q4-MOD3. determine the worth of ideas mentioned in the text listened toENG7-Q4-MOD3. determine the worth of ideas mentioned in the text listened to
ENG7-Q4-MOD3. determine the worth of ideas mentioned in the text listened to
 
Hungarian legislation made by Robert Miklos
Hungarian legislation made by Robert MiklosHungarian legislation made by Robert Miklos
Hungarian legislation made by Robert Miklos
 
Town of Haverhill's Summary Judgment Motion for Declaratory Judgment Case
Town of Haverhill's Summary Judgment Motion for Declaratory Judgment CaseTown of Haverhill's Summary Judgment Motion for Declaratory Judgment Case
Town of Haverhill's Summary Judgment Motion for Declaratory Judgment Case
 
RA. 7432 and RA 9994 Senior Citizen .pptx
RA. 7432 and RA 9994 Senior Citizen .pptxRA. 7432 and RA 9994 Senior Citizen .pptx
RA. 7432 and RA 9994 Senior Citizen .pptx
 
1990-2004 Bar Questions and Answers in Sales
1990-2004 Bar Questions and Answers in Sales1990-2004 Bar Questions and Answers in Sales
1990-2004 Bar Questions and Answers in Sales
 

Here are the answers to the review questions:1. 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 one is considered as a default multiplicity. 2. In a reflexive association, the instances of the same class can be related to each other. It states that a link or connection can be present within the objects of the same class. 3. Aggregation represents a weak "has-a" relationship where the child can exist independently of the parent. Composition represents a strong "part-of" relationship where the child cannot exist without the parent.4. Use case diagram describes

  • 1. Session 13: Class Diagram R2S Academy – Internal Use – Author: TUAN NGO
  • 2. Table of Content Class Diagram - Definition Examples Practice & Exercises R2S Academy – Internal Use – Author: TUAN NGO 1 2 3 Objectives
  • 5. 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
  • 6. 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
  • 7. 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
  • 9. Class Diagram Elements 1. Main components of a Class 2. Relationships
  • 10. Class Diagram Elements 1. Vital components of a Class 1.1. Upper Section 1.2. Middle Section 1.3. Lower Section 2. Relationships
  • 11. Class Diagram Elements 1. Vital components of a Class 1.1. Upper Section: name of the class ü Capitalize the initial letter of the class name ü Place the class name in the center of the upper section ü A class name must be written in bold format 1.2. Middle Section 1.3. Lower Section 2. Relationships
  • 12. 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
  • 13. 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
  • 14. Class Diagram Elements 1. Vital components of a Class 1.1. Upper Section 1.2. Middle Section 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
  • 15. Class Diagram Elements 1. Vital components of a Class 1.1. Upper Section 1.2. Middle Section 1.3. Lower Section: Signatures (Data types) 2. Relationships
  • 16. Class Diagram Elements 1. Vital components of a Class 2. Relationships 2.1. Association (Kết hợp) 2.2. Dependency (Phụ thuộc) 2.3. Generalization/ Inheritance (Kế thừa) 2.4. Realization (Hiện thực hóa)
  • 17. Class diagram Elements 1. Vital components of a Class 2. Relationships 2.1. Association (kết hợ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 one is considered as a default multiplicity
  • 18. Class diagram Elements 1. Vital components of a Class 2. Relationships 2.1. Association - Examples
  • 19. Class diagram Elements 1. Vital components of a Class 2. Relationships 2.1. Association 4 types of association ü unidirectional/ directed (một chiều) ü bi-directional (hai chiều) ü reflexive (phản xạ) ü aggregation (tập hợp) The mostly used associations are unidirectional and bi-directional.
  • 20. 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
  • 21. Class diagram Elements 1. Vital components of a Class 2. Relationships 2.1. Association ← Bi-directional Two objects might store each other in fields
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. Class diagram Elements Aggregation relationship Composition relationship Dependency In 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 Relationship Has-a relationship Part-of relationship Type of Association a weak association strong association Examples A 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. Vital components of a Class 2. Relationships 2.1. Association ← Aggregation ← Composition
  • 26. 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
  • 27. 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)
  • 28. Class diagram Elements 1. Vital components of a Class 2. Relationships 2.4. Realization (hiện thực hó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
  • 29. 1. Vital components of a Class 2. Relationships ü Exercise: Develop mind-map diagram for Class Diagram Relationships Class Diagram Elements
  • 30. 1. Vital components of a Class 2. Relationships Class Diagram Elements
  • 31. vs Use Case Diagram Class Diagram
  • 32. Class diagram Use case diagram vs Class diagram
  • 33. 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 Association Include Extend Generalization
  • 34. Use case diagram Class diagram What kind of? Behavioral diagram Structural diagram What describe? Describes functional requirements Describes 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 relationships Association, includes, extends, Generalization Association, Dependency, Generalization, Realization Specify Specify the behavior (what system will do?) Specify the internal structure that will help to complete a functionality mentioned in use cases Representation Use 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 execution Does not show the order in which steps are performed to achieve the goals of each use case Does not show the order in which classes executes
  • 36. Class Diagram Example 1 – Order System
  • 38. Class Diagram Example 3 ü Generalization/ Inheritance ü Realization
  • 42. Class Diagram Session Review Review content 1. What is multiplicity in Class diagram? 2. What is Reflexive association in Class diagram? 3. Aggregation relationship vs Composition relationship? 4. Use Case diagram vs Class diagram? 5. Mind-map diagram: develop a mind-map diagram to present all of Class diagram relationships types