association, aggregation and composition
I want to get the illustration for above three with simple classes. I read a lot from internet. The conclusion is as-
In aggregation people say-
“Class A contains collection of another Class (say B) and if A is destroyed it will not affect its child that is collection will not be destroyed.”
How is it possible if one object is destroyed but its property can still exist or what they mean by this.(Am I misinterpreting something)
Class A
{
List<B> lst;
}
Class B
{
}
Consider the following classes,
If you want to add a student to the department, then you call
AddStudent()and pass the reference of theStudentclass instance (note that a reference is passed). So when the department instance is destroyed (set tonullfor example), then theStudentsproperty of thatDepartmentinstance is no longer available, but theStudentinstances that have been used to populate this list remain are not destroyed. Hence, the property, in this case aStudentinstance can still exist.More information