Professional Documents
Culture Documents
Relationships in OOPs
Relationships in OOPs
RELATIONSHIPS
IN OOPS
SIT Internal
• Relationships in OOPs
LEARNING • “IS-A”
OUTCOM ES • “HAS-A”
• Dependency
SIT Internal
RELATIONSHIPS IN OOPS
Is-A Has-A
Inheritance Association
Aggregation Composition
SIT Internal
“IS- A” RELATIONSHIP
• Describes inheritance between classes
• Subclass being a specialized version of its superclass
INHERITANCE
Person
-
-
name
age
Person
- height
- eat()
- sleep()
Faculty
- staffId
- teachingSubject
Faculty - methodOfLecture()
Student
Student
- studentId
- methodOfStudy()
SIT Internal
Faculty
- staffId
- teachingSubject
Faculty - methodOfLecture()
Student
Student
- studentId
- methodOfStudy()
SIT Internal
“HAS- A” RELATIONSHIP
• Describes Association relationship between classes
ASSOCIATION
Weak Strong
Aggregation Composition
SIT Internal
AGGREGATION
• Whole-part relationship
• one class (the whole) contains one or more objects of another class (the part)
Part Whole
SIT Internal
AGGREGATION: EXAMPLE
Employee Department
}
SIT Internal
COMPOSITION
• Whole-part relationship
• one class (the whole) contains one or more objects of another class (the part)
• The associated objects are exclusive to the whole object and cannot exist
independently.
• When the whole object is destroyed, its parts are also destroyed.
Part Whole
SIT Internal
COMPOSITION: EXAMPLE
Engine Car
DEPENDENCY
• One class depends on another
• One class uses functionality or service of the other class
• Can exist between objects while they are associated, aggregated or
composed
Dependency Dependent
Class Class
SIT Internal
public Calculator() {
DEPENDENCY: EXAMPLE // Create an instance of the
MathLibrary to use its functions
this.mathLib = new MathLibrary();
}
Math Calculator
Library Class
• Calculator uses the functions from the "MathLibrary" to perform its mathematical
calculations.
• When the Calculator is created, it creates an instance of Math library as part of its
constructor
SIT Internal
CONCLUSION
• Different relationships in OOPs
• “is-a”: Inheritance
• “has-a”: Association
• Aggregation
• Composition
• Dependency