What is it called where child object gets killed if parent object is killed?
Answers
Answer is Composition.
Below are few concepts of Object Oriented Programming:
Association: All objects do not have ownership and possess their own life cycle.
Aggregation: It is a sub-category of Association. Objects possess own life cycle but has ownership; Child object is associated with only one parent object.
Composition: It is a strong and special form of Aggregation. Child does not possess a life cycle; So child dies when parent object is deleted; This is also called ‘death relationship’.
The sequence where child object gets killed if parent object is killed is called as composition.
Explanation:
Composition is one of the kinds of relationship in Java. It is a confined directional connection between items. Composition dependably pursues has-a sort of relationship.
Examples of composition are as follows:
A "college" has a few "divisions". Without presence of "college" there is no possibility for the "divisions" to exist. Consequently "college" and "offices" are emphatically related and this solid affiliation is known as creation.