??????.???????????????????????????
????1 package ?????;
????2
????3 public class Client {
????4
????5     public static void main(String[] args) {
????6
????7         System.out.println("=======?????????");
????8         IBread normalBread = new NormalBread();
????9         normalBread = new SweetDecorator(normalBread);
????10         normalBread = new CornDecorator(normalBread);
????11         normalBread.process();
????12         System.out.println("=======??????????");
????13     }
????14 }
??????.???
????1 =======?????????
????2 ????????????????...
????3 ??????????????
????4 ?????????...
????5 ????...
????6 ?????...????????????ˉ??
????7 =======??????????
????????????е?4?????
????(1)??????????Component:???????????????????????????????????????????????IBread???
????(2)?????????????ConcreteComponent:????Component?????????????????籾???е?NormalBread
????(3)?????Decorator:?????????????Component??????????????????Component??????????籾????AbstractBread
????(4)????????ConcreteDecorator1??ConcreteDecorator2:??????λ????????籾???е?CornDecorator??
????JDK?е????????
????java.io?к??????????????
???????????:FilterInputStream???(???)??InputStream??????BufferedInputStream?????FilterInputStream??
????1???????????????:??????????InputStream
????2.?????????????ConcreteComponent??FileInputStream??FileOutputStream?????????
????3.?????Decorator:FilterInputStream???????InputStream????????????????InputStream????
????protected volatile InputStream in;
????protected FilterInputStream(InputStream in) {
????this.in = in;
????}
????4.????????:??   BufferedInputStream  ???й?????????InputStream????????????
????public BufferedInputStream(InputStream in?? int size) {
????super(in);
????if (size <= 0) {
????throw new IllegalArgumentException("Buffer size <= 0");
????}
????buf = new byte[size];
????}
?????????????????????????????????????????????????????. (?????)
????1.InputStream-->IBread
????(??????InputStream??????????)
????2.FileInputStream-->NormalBread
????3.FilterInputStream-->AbstractBread
????(???Component????????InputStram.????????????????Component????????????????InputStream?????)
????4. BufferedInputStream  --> CornDecorator
????(?????????:??????λ?????????I?????nputStream?????????)
????(BufferedInputStream ??super(in)??CornDecorator?е?kneadFlour()?????????super.kneadFlour();?????????IO??????????????? )
????????JDK?е????????
???????ü?з?????????????????(?????????????)
????1.??????????????????????????????????????????????CornDecorator???NormalBread ??SweetDecorator ???NormalBread ????????????????????????????????????????????????????"???????"??"?????".
????2.?????????????????????????????(?????????????????????????????)????????SweetDecorator??? NormalBread?????CornSweetDecorator ???ü?? CornDecorator ???????????????????.
????2.???????????μ???????????????????????????????????????????м仹???????У?????????????????????SweetDecorator??? NormalBread?????OnionSweetDecorator???SweetDecorator????????CornOnionSweetDecorator ???OnionSweetDecorator??
????????????????????????????????????????????γ?????????????
????4.???????????????????????????????????????У?????????SweetDecorator ???????輴???????Client???д????????????????
??????ó???
????1.??????????ж??????????μ????????????????????????????
????2.??????????????????仯??????????????????????????????仯????????????