L9.Class Diagram
L9.Class Diagram
L9.Class Diagram
Introduction
<<friend>>
Iterator Vector
• Structural relationship
• Specifies that objects of one thing are connected to objects of
another
• Can navigate from objects of one class to the other
• Self Association
• Connects a class to itself
• Binary Association
• Connects exactly two classes
Association : Adornments
• Name
• Use a name to describe the nature of the relationship
• Can give a direction to the name
Association : Adornments
• Role
• The face that the class at the far end of the association presents to the class at
the near end
• Explicitly name the role a class plays (End name or Role name)
• Same class can play the same or different roles in other associations
Association : Adornments
• Multiplicity
• States how many objects may be connected across an
instance of an association
• An expression that evaluates to a range of values or an
explicit value
• Multiplicity at one end of an association means
• For each object of the class at the opposite end, there must be that many objects
at the near end
• Show a multiplicity of
• Exactly one (1)
• Zero or one (0 . . 1)
• Many (0 . . *)
• One or more (1 . . *)
• State an exact number (ex: 3)
Multiplicity
• 1:1
• 1:N
• N:1
• N:M
• Meta character – “*” and “+”:
Associations (cont.)
Role
name
Association
name
instructor
StaffMember Student
1..* instructs *
Role
Navigable
Multiplicit (uni-directional)
y association * pre -
requisites
Courses
0..3
Reflexive
association
2..* 1..*
Car Door House
Whole Part
1 Circle
Circle Point
3..* Point
Polygon
<<interface>>
LinkedList List ArrayList
44
Guidelines for Identifying a
Super-sub Relationship
• Top-down
Look for noun phrases composed of adjectives in a class
name.
• Bottom up
Look for classes with similar attributes or methods
Identifying the Composition &
Aggregation/a-part-of Relationship
• Composition - a physical whole is constructed from physical parts
(Assembly)
Eg1: Building constructed by bricks, stones
Eg2: ATM with Card Reader, Console, Printer, Key Pad
61
Revised class model for Library
System
.
62
Class Diagram Example