class Polygon {
private final LinkedHashSet <Line> polygon;
private int objID;
private static int classID;
Iterator <Line> it;
public Polygon(LinkedHashSet<Line> polygon) {
this.polygon = new LinkedHashSet<Line>();
for(Line l: polygon)
this.polygon.add (l);
objID = ++ classID;
it = this.polygon.iterator();
}
}
class Line {
Point start, end;
public Line(Point a, Point b){
start = a;
end = b;
}
}
在我的理解中,当我们在整体中构建“部分”对象时,关系是“组合”,这导致部分随整体一起被销毁。
在这种情况下,由于我们在构造函数中将新数据分配到多边形LinkedHashSet上并深度复制线对象,因此可以安全地假设这是多边形(作为整体)和线(作为部分)之间的“组合”关系吗?在这种情况下,当对象被销毁时,变量“polygon”中的数据肯定会被销毁。