<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)航:
     
    主站蜘蛛池模板: 免费真实播放国产乱子伦| 亚洲免费日韩无码系列| eeuss影院免费92242部| 国产成人A在线观看视频免费| 亚洲综合无码AV一区二区 | 老牛精品亚洲成av人片| 免费三级毛片电影片| 青青草原精品国产亚洲av| 国产特黄一级一片免费 | 亚洲一本到无码av中文字幕| 中文字幕成人免费视频| 久久久久久亚洲av成人无码国产| 免费无码午夜福利片| 免费精品国产自产拍观看| 亚洲a∨无码一区二区| 青青青青青青久久久免费观看| 亚洲国产成人久久99精品| 1000部拍拍拍18勿入免费视频软件 | 亚洲AV无码专区国产乱码电影 | 免费永久看黄在线观看app| 亚洲AV色欲色欲WWW| 好男人看视频免费2019中文| 亚洲精品日韩中文字幕久久久| 久久香蕉国产线看免费| 亚洲2022国产成人精品无码区| 国产一区二区免费视频| 亚洲五月六月丁香激情| 99久久人妻精品免费二区| 亚洲一区二区在线免费观看| 99热在线观看免费| 色爽黄1000部免费软件下载| 亚洲午夜AV无码专区在线播放| 一出一进一爽一粗一大视频免费的 | 日日夜夜精品免费视频| 在线观看日本免费a∨视频| 亚洲国产成人资源在线软件| 无人在线观看免费高清视频 | 亚洲电影一区二区| 免费一级毛片一级毛片aa| 免费的黄网站男人的天堂| 久久久亚洲精品蜜桃臀|