public abstract class AbstractFurniture implements Cloneable {
public abstract String draw();
protected Object clone() throws CloneNotSupportedException{
return super.clone();
}
}
public class CircleTable extends AbstractFurniture {
protected Point center;
public Point getCenter() {
return center;
}
public void setCenter(Point center) {
this.center = center;
}
public String draw() {
return center.toString();
}
protected Object clone() throws CloneNotSupportedException {
Object o = super.clone();
if(this.center != null) {
((CircleTable)o).setCenter((Point)center.clone());
}
return o;
}
}
public class SquareTable extends AbstractFurniture {
protected Rectangle rectangle;
public Rectangle getRectangle() {
return rectangle;
}
public void setRectangle(Rectangle rectangle) {
this.rectangle = rectangle;
}
public String draw() {
return rectangle.toString();
}
protected Object clone() throws CloneNotSupportedException {
Object o = super.clone();
if(this.rectangle != null) {
((SquareTable)o).setRectangle((Rectangle)rectangle.clone());
}
return o;
}
}