<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)航:
     
    主站蜘蛛池模板: 亚洲综合中文字幕无线码| 亚洲精品亚洲人成在线观看下载| 国产亚洲色婷婷久久99精品| 一个人晚上在线观看的免费视频| 亚洲精品无码永久在线观看 | 亚洲av日韩av无码av| 5g影院5g天天爽永久免费影院| 国产亚洲无线码一区二区 | 色猫咪免费人成网站在线观看| 久久精品国产96精品亚洲 | 久久亚洲精品11p| 日本中文一区二区三区亚洲| 美女视频黄.免费网址| 亚洲精品专区在线观看| 99久久精品毛片免费播放| 亚洲AV午夜成人影院老师机影院| 精品无码国产污污污免费网站| 亚洲1区1区3区4区产品乱码芒果 | 91精品免费久久久久久久久| 67194在线午夜亚洲| 免费国产真实迷j在线观看| 一级特黄录像视频免费| 亚洲精品亚洲人成人网| 亚欧色视频在线观看免费| 亚洲国产日韩精品| vvvv99日韩精品亚洲| 国产成人AV片无码免费| 久久久久精品国产亚洲AV无码| 国产精品jizz在线观看免费| 91成人免费福利网站在线| 亚洲国产精品综合福利专区| 国产网站在线免费观看| 国产在线国偷精品免费看| 亚洲欧洲中文日产| 亚洲A丁香五香天堂网| 久久国产乱子伦免费精品| 亚洲第一成年网站视频| 精品亚洲综合在线第一区| 欧洲精品成人免费视频在线观看| 日日摸夜夜添夜夜免费视频| 亚洲精品国产免费|