私はIntellij IDEA 2016.1.1を持っています。 なぜIntellij UMLダイアグラムでは、集計ではなくコンポジションラインが常に描画されますか?Javaのuml集約
マイコード:
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
学生クラスはAddressオブジェクトのライフサイクルを所有しているので、学生クラスに静的void mainメソッドがあるので少し混乱していると思います。主な方法をとり、完全に別のクラスに入れるとスチューデントオブジェクトがAddressオブジェクトの寿命を所有しないため、集約/関連付けになります。https://nirajrules.wordpress.com/2011/07/15/association-vs-dependency-vs-aggregation-vs-composition/ –