0

I wanted to ask how aggregation between same class is not a composition?? Example:

public class Person {
   private Person supervisor;
}

So here a person has a supervisor.

How this is considered as Aggregation, knowing that if I deleted Person supervisor will be deleted too.

Any explanations?

Danon
  • 2,771
  • 27
  • 37

1 Answers1

0

It depends on whether you do it like this

public class Person {
   private Person supervisor;

   Person(Person supervisor) {  // that's agregation
     this.supervisor = supervisor
   }
}

or like this

public class Person {
   private Person supervisor;

   void makeSupervision() {
     this.supervisor = new Person(); // that's composition
   }
}
Danon
  • 2,771
  • 27
  • 37