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;
}
}
In my understanding, when we construct the part object within the whole, the relationship is composition, which results in the part being destroyed along with the whole.
In this case since we allocate new data onto the polygon LinkedHashSet and deep-copy the Line objects in the constructor is it safe to assume this is a composition relationship between Polygon (being the whole) and Line (being the part)? In this case it definitely seems that the data in polygon
variable will be destroyed when the object is destroyed.