<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
    主站蜘蛛池模板: 亚洲色WWW成人永久网址| 免费国产a国产片高清| 亚洲av无码潮喷在线观看| 日本高清不卡中文字幕免费| 国产免费观看黄AV片| 亚洲色欲啪啪久久WWW综合网| 亚洲中文久久精品无码ww16| 夜夜爽妓女8888视频免费观看| 亚洲精品麻豆av| 中文字幕乱码系列免费| 亚洲美女又黄又爽在线观看| 七色永久性tv网站免费看| 亚洲欧洲第一a在线观看| 国产免费一区二区三区| 亚洲精品无码专区久久同性男| 男人扒开添女人下部免费视频| 亚洲高清最新av网站| 国产无遮挡又黄又爽免费网站| 午夜亚洲www湿好大| 1000部国产成人免费视频| 在线亚洲午夜片AV大片| 日本特黄特色aa大片免费| 菠萝菠萝蜜在线免费视频| 亚洲日韩国产精品第一页一区| 日韩免费高清大片在线| 中文字幕亚洲一区二区三区| 一个人免费视频观看在线www| 亚洲精品美女在线观看| 免费无码又爽又刺激高潮 | 国产亚洲精彩视频| 亚洲伊人久久成综合人影院| 国产成人AV片无码免费| wwwxxx亚洲| 亚洲熟妇无码另类久久久| 亚洲美女视频免费| 男女超爽视频免费播放| 亚洲国产一区二区a毛片| 在线播放免费播放av片| 国产一级高青免费| 久久亚洲精品国产亚洲老地址 | 女人被男人躁的女爽免费视频|