1700480462
图33-7 演技修饰
1700480463
1700480464
下面我们就来看看这些过程如何实现,先看明星接口,如代码清单33-33所示。
1700480465
1700480466
代码清单33-33 明星接口
1700480467
1700480468
public interface IStar{
1700480469
1700480470
//演戏
1700480471
1700480472
public void act();
1700480473
1700480474
}
1700480475
1700480476
我们来看看我们的主角,如代码清单33-34所示。
1700480477
1700480478
代码清单33-34 假明星
1700480479
1700480480
public class FreakStar implements IStar{
1700480481
1700480482
public void act(){
1700480483
1700480484
System.out.println(“演中:演技很拙劣”);
1700480485
1700480486
}
1700480487
1700480488
}
1700480489
1700480490
我们看看这个明星是怎么粉饰的,先定义一个抽象装饰类,如代码清单33-35所示。
1700480491
1700480492
代码清单33-35 抽象装饰类
1700480493
1700480494
public abstract class Decorator implements IStar{
1700480495
1700480496
//粉饰的是谁
1700480497
1700480498
private IStar star;
1700480499
1700480500
public Decorator(IStar_star){
1700480501
1700480502
this.star=_star;
1700480503
1700480504
}
1700480505
1700480506
public void act(){
1700480507
1700480508
this.star.act();
1700480509
1700480510
}
1700480511
[
上一页 ]
[ :1.700480462e+09 ]
[
下一页 ]