<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的結(jié)構(gòu)如下:

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

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

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

    decorator裝飾模式的解決方法就是,只實現(xiàn)基本功能,附加功能都抽出來,
    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();
    ??? }

    }
    這時需要實現(xiàn)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

    基礎(chǔ)的流只有左邊4個,這些流代表了數(shù)據(jù)的來源,所有的流都必須從這四個中之一開始(注,還有一個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

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲精品午夜在线观看| 亚洲AV无码码潮喷在线观看| 亚洲va在线va天堂va手机| 久久久免费的精品| 亚洲AV午夜成人片| 国产精品免费看久久久 | 亚洲国产综合人成综合网站| 亚洲欧洲专线一区| 免费毛片网站在线观看| 亚洲中文字幕一区精品自拍| 拨牐拨牐x8免费| 直接进入免费看黄的网站| 国产午夜免费福利红片| 曰批全过程免费视频免费看| 亚洲国产精品成人AV无码久久综合影院| 99亚洲精品卡2卡三卡4卡2卡| 国产传媒在线观看视频免费观看| 白白色免费在线视频| 亚洲综合另类小说色区| 一级毛片全部免费播放| 亚洲国产av一区二区三区丶| 午夜毛片不卡免费观看视频| 日韩在线视频免费| 亚洲国产精品一区二区久久hs| 最近免费中文字幕高清大全| 久久亚洲精品国产亚洲老地址 | 国产桃色在线成免费视频| 亚洲av片不卡无码久久| 日韩电影免费在线| 中文字幕一区二区三区免费视频| 亚洲精品私拍国产福利在线| 成人浮力影院免费看| 在线91精品亚洲网站精品成人| 亚洲色中文字幕无码AV| 成人免费视频69| 特级毛片全部免费播放a一级| 亚洲色大成网站www永久一区| 18禁美女黄网站色大片免费观看 | 精品女同一区二区三区免费播放 | 一二三四视频在线观看中文版免费 | 久九九精品免费视频|