<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是你的擴(kuò)展類,decoratorA,decoratorB封裝了你要擴(kuò)展的功能,并保持了
    MyInterface的引用

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

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

    decorator裝飾模式的解決方法就是,只實(shí)現(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();
    ??? }

    }
    這時(shí)需要實(shí)現(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個(gè),這些流代表了數(shù)據(jù)的來源,所有的流都必須從這四個(gè)中之一開始(注,還有一個(gè)RandomAccessFile、File,這兩個(gè)不在本文介紹范圍)。
    當(dāng)我們需要什么新功能的時(shí)候就在右邊找個(gè)裝飾類,在用到緩存的時(shí)候我們就用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) 評(píng)論(0)  編輯  收藏 所屬分類: Java

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 成人免费午夜无码视频| 一级毛片在线免费视频| 久久国产免费福利永久| 亚洲欧洲日韩不卡| 99re6在线精品视频免费播放| 亚洲AV无码精品无码麻豆| 日韩av无码免费播放| 亚洲国产精品嫩草影院在线观看| a级男女仿爱免费视频| 九月丁香婷婷亚洲综合色| 亚洲欧洲免费视频| 亚洲国产精品成人久久久| 中字幕视频在线永久在线观看免费| tom影院亚洲国产一区二区| 女人张开腿给人桶免费视频| 亚洲精华液一二三产区| 九月婷婷亚洲综合在线| 久久免费国产精品| 91情国产l精品国产亚洲区 | 一边摸一边桶一边脱免费视频| 亚洲福利中文字幕在线网址| 精品熟女少妇aⅴ免费久久| 亚洲av最新在线网址| 青青久在线视频免费观看| 麻豆亚洲AV成人无码久久精品 | 久久不见久久见免费影院www日本| 久久精品国产亚洲夜色AV网站| 99xxoo视频在线永久免费观看| 亚洲中文字幕无码爆乳| 国产亚洲av片在线观看18女人| 91精品手机国产免费| 久久久久久亚洲av无码蜜芽 | 久久精品国产亚洲AV麻豆~| 1000部禁片黄的免费看| 亚洲AV无码一区二区三区电影| 国产亚洲精品无码专区| 2021在线永久免费视频| 日韩精品免费一线在线观看| 亚洲国产成人久久综合一| 免费的一级片网站| 日韩免费在线视频|