Ich habe Intellij IDEA 2016.1.1. Warum zeichnet das Intellij-UML-Diagramm immer eine Kompositionslinie statt einer Aggregation?Uml Aggregation in Java
Mein Code:
public class Address {
int streetNum;
String city;
String state;
String country;
Address(int street, String c, String st, String coun)
{
this.streetNum=street;
this.city =c;
this.state = st;
this.country = coun;
}
}
public class StudentClass {
int rollNum;
String studentName;
Address studentAddr;
StudentClass(int roll, String name, Address addr){
this.rollNum=roll;
this.studentName=name;
this.studentAddr = addr;
}
public static void main(String args[]){
Address ad = new Address(55, "Agra", "UP", "India");
StudentClass obj = new StudentClass(123, "Chaitanya", ad);
System.out.println(obj.rollNum);
System.out.println(obj.studentName);
System.out.println(obj.studentAddr.streetNum);
System.out.println(obj.studentAddr.city);
System.out.println(obj.studentAddr.state);
System.out.println(obj.studentAddr.country);
}
}
Sie sehen können, ist diese Linie Zusammensetzung beschrieben? Warum?
Intellij Unentschieden:
Ich bin nicht sehr vertraut mit Intellij, aber Ihre Student-Klasse enthält die Hauptmethode, in der die Objekte instanziiert werden. Wenn Sie eine separate Klasse für die Hauptmethode erstellen, sollte diese nicht mehr als Komposition angezeigt werden. –
Ich weiß das. Warum? ( – Sustav
Da die Student-Klasse den Lebenszyklus des Address-Objekts besitzt. Ich denke, es ist ein wenig verwirrend, da Sie Ihre static void main-Methode in Ihrer Student-Klasse haben. Wenn Sie Ihre Hauptmethode verwenden und in eine völlig separate Klasse einfügen Es wäre Aggregation/Association, weil das Objekt Student nicht das Leben des Address-Objekts besitzen würde. https://nirajrules.wordpress.com/2011/07/15/association-vs-dependency-vs-aggregation-vs-composition/ –