Relationships Between Classes
Relationships Between Classes
between classes
2023
Contents:
❖ Relationships introduction
❖ Dependencies
❖ Association, Aggregation &
Composition
❖ Inheritance & Realize
Section 1
RELATIONSHIPS
INTRODUCTION
Relationships introduction
DEPENDENCIES
Dependencies
◼ A dependency expresses the relationship
between a supplier A and a client B that relies on
it. There is a dependency because changes in
the supplier A can effect the client B. In this case,
class B depends on class A
◼ Weaknest class relationship:
➢ A class using another as parameter passed in a
method (most cases)
➢ A class using another inside a method
Dependencies
◼ Ex: The car relies on gasoline. If there is no
gasoline, the car will not be able to drive
Dependencies
ASSOCIATION, AGGREGATION
& COMPOSITION
Association relationships
◼ Association: Indicates that a property of a
class holds a reference to an instance (or
instances) of another class
◼ Association is the most commonly used
relationship between a class and a class,
which means that there is a connection
between one type of object and another
type of object.
Association relationships
◼ Ex1: Cars and Drivers, one Car
corresponds to a particular Driver, and one
Driver can drive multiple Cars
Association relationships
◼ Ex: The Student class and the Course Offering
class -> the Student is registering for the Course
Offering. So, in a sense, the Course Offering
“has” students – contains students.
Association relationships
We can add a label to an association to describe the
nature of the relationship. In this case, it clarifies that
the student registers for CourseOffering
Association relationships