0
我Intellij IDEA 2016.1.1。 爲什麼Intellij UML圖總是繪製組合線而不是聚合?uml聚合在Java
我的代碼:
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);
}
}
可以看到,該行被描述組成? 爲什麼?
的IntelliJ抽獎:
我對intellij不是很熟悉,但是你的學生類包含實例化對象的主要方法。如果您要爲主要方法創建單獨的類,則不應再顯示爲組合。 –
我知道這一點。爲什麼? ( – Sustav
因爲Student Class擁有Address對象的生命週期,所以我覺得有點困惑,因爲你在你的Student類中有static void main方法,如果你把你的主要方法放到一個完全獨立的類中,它會是Aggregation/Association,因爲學生對象不會擁有Address對象的生命。https://nirajrules.wordpress.com/2011/07/15/association-vs-dependency-vs-aggregation-vs-composition/ –