??????.???????????????????
???????????????IBread?????????????????????IBread???????
??????????????2??????:??????????????????????????
1 package ?????;
2
3 public abstract class AbstractBread implements IBread {
4
5     private final IBread bread;
6
7     public AbstractBread(IBread bread) {
8         super();
9         this.bread = bread;
10     }
11     @Override
12     public void prepair() {
13         this.bread.prepair();
14     }
15     @Override
16     public void kneadFlour() {
17         this.bread.kneadFlour();
18     }
19     @Override
20     public void steamed() {
21         this.bread.steamed();
22     }
23
24     @Override
25     public void process() {
26         prepair();
27         kneadFlour();
28         steamed();
29     }
30
31 }
??????.?????????????"???????"
???????AbstarctBread???????????????????????????????????????????з???????????????????????????????
?????????????????????
??????????????1??????:???????????????????????
1 package ?????;
2
3 public class CornDecorator extends AbstractBread{
4
5     public CornDecorator(IBread bread) {
6
7         super(bread);
8     }
9
10     public void paint(){
11
12         System.out.println("??????????????");
13     }
14     @Override
15     public void kneadFlour() {
16         //?????????????
17         this.paint();
18         super.kneadFlour();
19     }
20
21
22 }
??????.?????????????"?????"
????????????????
1 package ?????;
2
3 public class SweetDecorator extends AbstractBread {
4
5     public SweetDecorator(IBread bread) {
6
7         super(bread);
8     }
9
10     public void paint(){
11
12         System.out.println("?????????...");
13     }
14
15     @Override
16     public void kneadFlour() {
17         //?????????????
18         this.paint();
19         super.kneadFlour();
20     }
21
22 }