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/ –