interface DrawingAPI {
void drawCircle(int x, int y, int radius);
}
class DrawingAPI1 implements DrawingAPI {
public void drawCircle(int x, int y, int radius) {
System.out.printf("API1.circle at %d:%d radius %d\n", x, y, radius);
}
}
class DrawingAPI2 implements DrawingAPI {
public void drawCircle(int x, int y, int radius) {
System.out.printf("API2.circle at %d:%d radius %d\n", x, y, radius);
}
}
abstract class Shape {
protected DrawingAPI drawingAPI;
protected Shape(DrawingAPI drawingAPI){
this.drawingAPI = drawingAPI;
}
public abstract void draw();
public abstract void resizeByPercentage(double pct);
}
class CircleShape extends Shape {
private int x, y, radius;
public CircleShape(int x, int y, int radius, DrawingAPI drawingAPI) {
super(drawingAPI);
this.x = x;
this.y = y;
this.radius = radius;
}
public void draw() {
drawingAPI.drawCircle(x, y, radius);
}
public void resizeByPercentage(double pct) {
radius *= pct;
}
}
暂无评论