Lec 04 Class Diagram
Lec 04 Class Diagram
Nalinadevi Kadiresan
CSE Dept.
Amrita School of Engg.
19CSE204 Object oriented Programming 2
• attributes (optional)
– should include all fields of the object
Class attributes
• attributes (fields, instance variables)
– visibility name : type [count] = default_value
– visibility: + public
# protected
- private
~ package (default)
/ derived
– underline static attributes
– derived attribute: not stored, but can
be computed from other attribute values
– attribute example:
- balance : double = 0.00
Generalization relationships
• generalization (inheritance) relationships
– hierarchies drawn top-down with arrows pointing
upward to parent
– line/arrow styles differ, based on whether parent is
a(n):
• class:
solid line, black arrow
• abstract class:
solid line, white arrow
• interface:
dashed line, white arrow
– we often don't draw trivial / obvious generalization
relationships, such as drawing the Object class as
a parent
June 2021 Nalinadevi Kadiresan
19CSE204 Object oriented Programming 9
Associational relationships
• associational (usage) relationships
1. multiplicity (how many are used)
• * 0, 1, or more
• 1 1 exactly
• 2..4 between 2 and 4, inclusive
• 3..* 3 or more
2. name (what relationship the objects have)
3. navigability (direction)
Multiplicity of associations
one-to-one
each student must carry exactly one ID card
one-to-many
one rectangle list can contain many rectangles
10
19CSE204 Object oriented Programming 11
Multiplicity
Class Course {
Student have[];
}
1
aggregation
1
Association types Engine
• aggregation: “has-a"
– symbolized by a clear white diamond Book
composition
• composition:”part-off” / "is entirely made 1
of" *
– stronger version of aggregation
Page
– the parts live and die with the whole
– symbolized by a black diamond
Association Types
• Aggregation implies a relationship where the
child can exist independently of the parent.
• Composition implies a relationship where the
child cannot exist independent of the parent.
• Composition is a strong Association whereas
Aggregation is a weak Association
Association
Association
Multiplicity
Aggregation
[]
Composition
Interface Services
.
• Interfaces do not get instantiated. They have no
attributes or state. Rather, they specify the
services offered by a related class
<<interface>>
ControlPanel
getChoices : Choice[]
makeChoice (c : Choice)
getSelection : Selection
Description:
A customer arrives to acquire the vehicle and depart
for desired destination. The vehicle reservation
contract is signed and the vehicle is released to the
customer.