打字猴:1.700477359e+09
1700477359 //丑小鸭的外形
1700477360
1700477361 public void desAppaearance(){
1700477362
1700477363 System.out.println(“外形是脏兮兮的白色,毛茸茸的大脑袋”);
1700477364
1700477365 }
1700477366
1700477367 //丑小鸭还比较小,不能飞
1700477368
1700477369 public void fly(){
1700477370
1700477371 System.out.println(“不能飞行”);
1700477372
1700477373 }
1700477374
1700477375 }
1700477376
1700477377 丑小鸭具备了天鹅的所有行为和属性,因为她本来就是一只白天鹅,只是因为她太小了还不能飞行,也不能照顾自己,所以丑丑的,在经过长时间的流浪生活后,丑小鸭长大了。终于有一天,她发现自己竟然变成了一只美丽的白天鹅,有着漂亮、洁白的羽毛,而且还可以飞行,这完全是一种升华行为。那我们来看看她的行为(飞行)和属性(外形)是如何加强的,先看抽象的装饰类,如代码清单31-9所示。
1700477378
1700477379 代码清单31-9 抽象装饰类
1700477380
1700477381 public class Decorator implements Swan{
1700477382
1700477383 private Swan swan;
1700477384
1700477385 //修饰的是谁
1700477386
1700477387 public Decorator(Swan_swan){
1700477388
1700477389 this.swan=_swan;
1700477390
1700477391 }
1700477392
1700477393 public void cry(){
1700477394
1700477395 swan.cry();
1700477396
1700477397 }
1700477398
1700477399 public void desAppaearance(){
1700477400
1700477401 swan.desAppaearance();
1700477402
1700477403 }
1700477404
1700477405 public void fly(){
1700477406
1700477407 swan.fly();
1700477408
[ 上一页 ]  [ :1.700477359e+09 ]  [ 下一页 ]