Relationships - Day 4 Flashcards
3 ways to associate relationships between two classes
Reuse members of a class in another
Aggregation
Association
Inheritance
Association
Uses-a relationship
I.e Patient makes an appointment Vs A driver uses a car
Association is represented by an arrow in a class diagrams.
Aggregation
“Has a” type of relationship
Inheritance
“Is a” relationship.
Can have multiple sub classes.
When a class inherits from another class
Inheritance hierarchy
Parent class
^
|
Child class
Parents have multiple children
Inheritance of private, public etc.
Static and private cannot be inherited
No need for a parent type object with public inheritance
Inheritance uses what keyword
Extend
Super constructor
“super();” Has to be the first statement inside a constructor!
Types of inheritance
Single inheritance
Multilevel inheritance
Hierarchical inheritance
Multiple inheritance
Single inheritance
One class is extended by one class
Multilevel inheritance
A class extends another class which extended another class
Grandad - dad - son
Hierarchical inheritance
Multiple classes extend the same base class
Multiple inheritance
One class extends multiple classes.
Class 1 Class 2
(Don’t have to know this one as it’s not supported in Java)