Classes &relnships
Classes &relnships
DA-IICT
Saurabh Tiwari
OO Concepts
1
9/16/24
Polymorphism
?
tion?
aliza
ener
t is G
Wha
2
9/16/24
Class Modeling
Objects
Consists of
• Identifier
• Values
• Behavior
3
9/16/24
Classes
4
9/16/24
Classes
Objects
Class
10
5
9/16/24
Class Diagrams
All objects of this class (instances of this class) share the same
behaviour, and have the same set of attributes (each object has its
own set).
Class Diagrams
6
9/16/24
Class Diagrams
Attributes
In UML, Attributes are shown with at
least their name, and can also show
their type, initial value and other
properties. Attributes can also be
displayed with their visibility:
+ public attributes
# protected attributes
- private attributes
Class Diagrams
Operations
+ public operations
# protected operations
- private operations
7
9/16/24
15
16
8
9/16/24
Object Relationships
• Association
• Aggregation
• Composition
• Inheritance
• Dependency
17
anAssociation aLink
A B anA:A aB:B
* *
anAssociation aLink
A *anotherAssociation* B anA:A aB:B
* * anotherLink
18
9
9/16/24
Association
19
Multiplicity
• “One” or “Many”
• Infinite (subset of the nonnegative integers)
20
10
9/16/24
Association
Visual representation
One-to-one association
21
Association
Many-to-one association
Person Company
OwnStock
name name
* *
Many-to-many association
22
11
9/16/24
Interpretation?
Person and Company participate in association “WorkFor”
23
Workstation Window
name type
1 1
Workstation Window
console
name type
1 0..1
24
12
9/16/24
25
Question?
Parent Child
name name
2 *
Person
name Parent
0..2
Child *
26
13
9/16/24
• Ordered means that the objects are ordered in the collection of associated
elements.
• Sequence means that the association implements an ordered bag, that is an
ordered collection of elements where the same elements may occur several times
27
Question?
Man Women
{……}
Ordered
Sequence
28
14
9/16/24
Association Class
Salary ?
Job Title ?
29
Association Class
Salary ?
Job Title ?
30
15
9/16/24
Association Class
31
Association Class
32
16
9/16/24
Association Class
Ordinary Class
33
Question?
34
17
9/16/24
Qualified Association
• Both below models are acceptable but the qualified model adds
information.
35
Qualified Association
36
18
9/16/24
N-ary Association
Programmer
Class Diagram
37
N-ary Association
Instance Diagram
38
19
9/16/24
39
40
20
9/16/24
Summary
41
Next Lecture…
Object Relationships: Association (Aggregation,
Composition) & Inheritance, Dependency
21
9/16/24
Generalization/Inheritance
22
9/16/24
Use of generalization
Aggregation
23
9/16/24
24
9/16/24
25
9/16/24
Propagation of operations
Exercises
26
9/16/24
chairs
0..1
Department 1
assigned to 1..*
1..*
1..*
Instructor
1
offers
teaches
1..* 0..3
27
9/16/24
10..*
Assigned To Artifact
Employee 1..* Project 1
1
1 0..*
Managed By History Log
0..n
History Entry
Code Bug Report
-when : Date
-whatDone : string
28
9/16/24
Questions??
29