阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
欲开发一个绘图软件,要求使用不同的绘图程序绘制不同的图形。以绘制直线和圆形为例,对应的绘图程序如表6-1所示。
表6-1 不同的绘图程序
该绘图软件的扩展性要求,将不断扩充新的图形和新的绘图程序。为了避免出现类爆炸的情况,现采用桥接(Bridge)模式来实现上述要求,得到如图6-1所示的类图。
图6-1 类图
【Java代码】
(1) Drawing{
(2) ;
(3) ;
}
class DP1{
static public void draw_a_line(double x1, double y1, double x2, double y2) {/*代码省略*/}
static public void draw_a_circle(double x, double y, double r) {/*代码省略*/}
}
class DP2{
static public void drawline(double x1, double y1, double x2 ,double y2){/*代码省略*/}
static public void drawcircle (double x, double y, double r){/*代码省略*/}
}
class V1Drawing implements Drawing{
public void drawLine(double x1, double y1, double x2 ,double y2){/*代码省略*/}
public void drawCircle(double x, double y, double r){ (4) ;}
}
class V2Drawing implements Drawing{
public void drawLine(double x1, double y1, double x2 ,double y2){/*代码省略*/}
public void drawCircle (double x, double y, double r){ (5) ;}
}
abstract class Shape{
private Drawing _dp;
(6) ;
Shape(Drawing dp) {_dp=dp;}
public void drawLine(double x1, double y1, double x2 ,double y2){_dp.drawLine(x1,y1,x2,y2); }
public void drawCircle (double x, double y, double r){ _dp.drawCircle(x,y,r);}
}
class Rectangle extends Shape{
private double _x1,_x2,_y1,_y2;
public Rectangle(Drawing dp,double x1, double y1, double x2 ,double y2) {/*代码省略*/}
public void draw(){/*代码省略*/}
}
class Circle extends Shape{
private double _x, _y, _r;
public Circle(Drawing dp,double x, double y, double r) {/*代码省略*/}
public void draw(){drawCircle(_x,_y,_r);}
}