<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 緣來如此 閱讀(347) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲国产精品成人久久| 亚洲不卡无码av中文字幕| 久久久婷婷五月亚洲97号色 | 久久99精品免费一区二区| 亚洲色图综合在线| 一级免费黄色大片| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 日韩免费一区二区三区在线 | 亚洲日韩中文无码久久| 国产免费人成视频尤勿视频| 国产偷窥女洗浴在线观看亚洲| 亚洲第一视频在线观看免费| 2022中文字字幕久亚洲| 成全视频在线观看免费| 久久亚洲AV成人无码国产 | 久久国产精品免费看| 精品亚洲成a人片在线观看| 91免费国产自产地址入| 亚洲www在线观看| 国产高清免费在线| 一级毛片在播放免费| 久久精品国产亚洲av麻豆| 亚洲最大免费视频网| 亚洲国产精品无码中文lv| 亚洲国产人成中文幕一级二级| 中文在线观看免费网站| 亚洲视频中文字幕在线| 免费观看的av毛片的网站| ssswww日本免费网站片| 亚洲成人午夜在线| 成人免费a级毛片| 四虎影视久久久免费| 亚洲天堂中文字幕| 成人永久福利免费观看| 久久免费99精品国产自在现线| 久久亚洲日韩看片无码| 免费欧洲毛片A级视频无风险| 国产婷婷成人久久Av免费高清| 亚洲一区二区三区深夜天堂| 亚洲国产成人久久综合区| 免费人妻无码不卡中文字幕系|