<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 31  文章 - 2  trackbacks - 0
    decorator的結構如下:

    ????MyInterface
    ???????|
    _______|_______
    |?????????????|?
    Myclass?????Decorator
    ??????????____|_____
    ??????????|????????|?
    ??DecoratorA??????DecoratorB
    decorator的目的是在不改變基礎類的前提下,添加新的功能(在比較少的子類前提),Myclass是你的擴展類,decoratorA,decoratorB封裝了你要擴展的功能,并保持了
    MyInterface的引用

    考慮一下代碼
    public static void main(String[]args){
    ? MyInterface a=new Myclass();
    ??? a.print();

    }
    ?MyInterface是Myclass的接口,在 MyInterface里面就聲明了一個print方法,myclass實現了該方法
    public void print(){
    System.out.print("hello");
    }
    如果我們要實現打印 ”hello word“,”my hell“就要要寫很多類似的類,

    decorator裝飾模式的解決方法就是,只實現基本功能,附加功能都抽出來,
    public decoratorA
    implements?Decorator{
    ???
    MyInterface?myObject;
    ??? public decoratorA(MyInterface my){
    ??? ??
    myObject=my;
    ??? }
    ??? public void print(){
    ??? ?? System.out.print("
    world ");
    ??? }

    }

    public decoratorB implements?Decorator{
    ???
    MyInterface?myObject;
    ??? public decoratorB(MyInterface my){
    ??? ??
    myObject=my;
    ??? }
    ??? public void print(){
    ??? ?? System.out.print("MY
    ");
    ??? ?? ??
    myObject.print();
    ??? }

    }
    這時需要實現my hello word就比較簡單了
    public void main(String[]args){
    MyInterface a=new decoratorA (new decoratorB(new Myclass()) );
    a.print();
    }

    BufferedInputStream?bis?=?new?BufferedInputStream(new?DataInpuStream(new?FileInputStream("xxx.txt")));

    InputStream.為例:
    ? ??? ??? ??? java.io.InputStream
    ????????????????????????|
    ?_______________________|________________________
    ?|?????????????????????????????????????????????|
    ByteArrayInputStream??????????????????????FilterInputStream
    StringBufferInputStream???_____________________|____________________________
    FileInputStream???????????|????????????????|????????????????????|??????????|
    PipedInputStream??DataInputStream?BufferedInputStream??LineNumInpuStream
    PushbackInputStream

    基礎的流只有左邊4個,這些流代表了數據的來源,所有的流都必須從這四個中之一開始(注,還有一個RandomAccessFile、File,這兩個不在本文介紹范圍)。
    當我們需要什么新功能的時候就在右邊找個裝飾類,在用到緩存的時候我們就用bufferedInputStream

    BufferdInputStream?is?=?new?BufferedInputStream(new?FileInputStream("xxx.txt"));


    假如再要DataInputStream的功能,只要在加一層:
    DataInputStream?dis?=?new?DataInputStream(new?BufferdInputStream(new?FileInputStream));




















    posted on 2008-04-20 11:35 緣來如此 閱讀(352) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲va中文字幕无码久久不卡| 在线观看免费成人| 亚洲国产综合久久天堂| 亚洲av无码成人影院一区| 国产成人A在线观看视频免费| 亚洲男人的天堂在线| 69xx免费观看视频| 亚洲欧洲日韩综合| 看全色黄大色大片免费久久| 色偷偷亚洲第一综合| 国产亚洲欧洲Aⅴ综合一区| 你懂的免费在线观看| 亚洲AV无码专区国产乱码4SE | 国产精品亚洲mnbav网站| 国产99视频精品免费专区| 久久国产亚洲高清观看| 免费人成视频在线| 麻花传媒剧在线mv免费观看| 国内精品久久久久影院亚洲| 在线观看免费精品国产| 国产日韩AV免费无码一区二区| 亚洲国产精品成人精品小说| 亚洲国产精品久久久久婷婷软件 | 国产成人麻豆亚洲综合无码精品 | 亚洲成AV人在线播放无码| 在线视频精品免费| 全部在线播放免费毛片| 亚洲av中文无码乱人伦在线播放| 国产亚洲精品国看不卡| 国产91精品一区二区麻豆亚洲| 免费在线观看理论片| 黄+色+性+人免费| 91免费国产自产地址入| 免费观看无遮挡www的小视频| 中文字幕免费在线| 免费在线人人电影网| 美女扒开尿口给男人爽免费视频| 亚洲午夜未满十八勿入| 精品无码一区二区三区亚洲桃色 | 粉色视频成年免费人15次| 亚洲成a人片77777群色|