1

Can someone please explain me what is type of aggregation is and why for that the vector should not be initialized and this code is according to diagram? What I don't understand why when is -> at the end of aggregation or composition the vector shouldn't be internalized.

class Project
{
 private Vector<Student> stds;
 private Vector<Diag> diagra = new Vector();
}

UML:enter image description here

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • 1
    What about is your question, UML or Java? – qwerty_so Jul 05 '21 at 18:41
  • @qwerty_so both, 1. what is the difference betwenn aggregation\compozition with ---- and -----> 2. why for first is inot ntantiated the vector and for the second is ? –  Jul 05 '21 at 18:50
  • I would have closed your question re UML since https://stackoverflow.com/questions/885937/what-is-the-difference-between-association-aggregation-and-composition Asking 2 questions in one is not a good fit here. Anyhow, since Christophe has already given an answer re Java I'll leave it as it is. – qwerty_so Jul 06 '21 at 07:31

1 Answers1

2

This code does not allow to make a difference between association, aggregation, composition. The initialization or not of the vector is not relevant.

The UML says that a Project has an unspecified number of Student. Since it is aggregation, there is no exclusive ownership, sot the same students can appear in several projects. ALsi, when the project is destroyed, all its students remain unaffected.

  • The Java code leaves stds unitialized. This says nor guarantees anything about ownership of the Student.
  • Moreover, the Java code will have at one moment or the other to properly initialize the stds vector if the project is supposed to aggregate some students.
  • In fact, I suspect the author of the code to confuse aggregation with the object assignment in Java. Aggregation is a modeling placebo that does not have this meaning. It is much simpler and less ambiguous to use a simple association instead of an agregation in this case.

The UML says the a Project is a composite that has an unspecified number of Diag. The composition means an exclusive ownership, not of the vector, but of the diagrams that are stored within:

  • The java code uses vector that is initialized to an empty vector, which tells nothing about teh lifeclycle and ownership of the objects it will contain.
  • In fact, the vector elements are references (“object handles”) that can always be shared. Nothing guarantees the ownership of the diagrams in the code.
Christophe
  • 68,716
  • 7
  • 72
  • 138