Inheritance Flashcards
What is INHERITANCE?
Process whereby one object inherits the properties
(states and behaviours) of another object (pairs
called super/sub or parent/child classes)
The Java keyword that implies inheritance is
extends
What are the ADVANTAGES of INHERITANCE?
- Minimizing the amount of duplicate code in an application by sharing common code amongst several subclasses
- Minimize the amount of duplicate code in an application
- Better organization of code
- Code more flexible to change
Explain MINIMIZE DUPLICATE CODE
If duplicate code (variables and methods) exists in two related classes, they can be refactored into a hierarchy by moving that common code up to a common superclass
Explain BETTER ORGANIZATION OF CODE
Moving common code to a super class results in
better organization of code (better abstraction)
Explain CODE MORE FLEXIBLE TO CHANGE
Inheritance can also make application code more
flexible to change because classes that inherit from a
common super class can be used interchangeably
What is are all different types of inheritance?
- Association
- Aggregation
- Dependency
What is ASSOCIATION?
The objects are separate entities from each other (and can exist without each other), but associate and interact with each other in a relationship that may be one-to-one, one-to-many, or many-to-many
What is AGGREGATION?
When a connection between objects is mandatory for at least one of them
What is DEPENDENCY?
Dependency is an umbrella term used to denote one class being dependent on another. Inheritance, association and aggregation are specialised forms of dependency.
We use dependency for temporary relations