<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    模式筆記一:如何學(xué)習(xí)模式

    啥叫模式? Patterns in solutions come from patterns in problems.
    針對(duì)某一類(lèi)經(jīng)常出現(xiàn)的問(wèn)題所采取的行之有效的解決方案
    "A pattern is a solution to a problem in a context."

    "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice."(Christopher Alexander -- A Pattern Language)

    模式的四個(gè)基本要素:
    1. 模式名稱(chēng)pattern name
    2. 問(wèn)題problem
    3. 解決方案solution
    4. 效果consequences

    如何描述設(shè)計(jì)模式(十大特點(diǎn))
    1. 意圖:描述,別名
    2. 動(dòng)機(jī):場(chǎng)景
    3. 適用性: 什么情況下
    4. 結(jié)構(gòu): 類(lèi)圖, 序列圖
    5. 參考者
    6. 協(xié)作
    7. 效果
    8. 實(shí)現(xiàn)
    9. 應(yīng)用
    10. 相關(guān)模式

    在實(shí)踐中學(xué)習(xí)是最佳的方式, 所以先要掌握每個(gè)模式的十大特點(diǎn),更加重要的是在實(shí)際應(yīng)用中學(xué)習(xí), 在水中學(xué)會(huì)游泳
    以迭代器模式為例, Java中有一個(gè)Iterator接口
     1 public interface Iterator
     2 {
     3   /**
     4    * Tests whether there are elements remaining in the collection. In other
     5    * words, calling <code>next()</code> will not throw an exception.
     6    *
     7    * @return true if there is at least one more element in the collection
     8    */
     9   boolean hasNext();
    10 
    11   /**
    12    * Obtain the next element in the collection.
    13    *
    14    * @return the next element in the collection
    15    * @throws NoSuchElementException if there are no more elements
    16    */
    17   Object next();
    18 
    19   /**
    20    * Remove from the underlying collection the last element returned by next
    21    * (optional operation). This method can be called only once after each
    22    * call to <code>next()</code>. It does not affect what will be returned
    23    * by subsequent calls to next.
    24    *
    25    * @throws IllegalStateException if next has not yet been called or remove
    26    *         has already been called since the last call to next.
    27    * @throws UnsupportedOperationException if this Iterator does not support
    28    *         the remove operation.
    29    */
    30   void remove();
    31 }
    32 
    假如你的類(lèi)中有一些聚集關(guān)系, 那么考慮增加一個(gè)iterator方法,以實(shí)現(xiàn)下面這個(gè)接口
    public interface Iterable
    {
      
    /**
       * Returns an iterator for the collection.
       *
       * 
    @return an iterator.
       
    */
      Iterator iterator ();
    }

    返回你自己實(shí)現(xiàn)的ConcreteIterator類(lèi), 這個(gè)ConcreteIterator當(dāng)然是實(shí)現(xiàn)了Iterator接口的
    你會(huì)發(fā)現(xiàn)在遍歷和迭代類(lèi)中的這個(gè)成員的聚集元素時(shí)會(huì)有不同的感覺(jué), 因?yàn)檫@個(gè)Iterator與實(shí)現(xiàn)是分離的.
    你的類(lèi)終歸是給自己或別人使用的,在調(diào)用者的眼里, 非常簡(jiǎn)單, 管你里面是怎么實(shí)現(xiàn)的呢,
    反正我知道你能給我一個(gè)迭代器就夠了, 這里面就體現(xiàn)了面向接口編程的好處. 也就是按契約編程

    posted on 2008-08-10 21:07 fantasyamin 閱讀(253) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Java

    <2008年8月>
    272829303112
    3456789
    10111213141516
    17181920212223
    24252627282930
    31123456

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(1)

    隨筆分類(lèi)

    隨筆檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 国产精品亚洲mnbav网站| 无码乱人伦一区二区亚洲| 亚洲AV无码精品蜜桃| 久久永久免费人妻精品下载| 亚洲一区二区三区免费视频| 亚洲网红精品大秀在线观看| 国产成年无码久久久免费| 亚洲AV无码成人精品区在线观看 | 久久精品国产亚洲AV电影| 亚洲国产成人综合精品| 67pao强力打造67194在线午夜亚洲| 久久亚洲中文无码咪咪爱| 在线91精品亚洲网站精品成人| 曰批全过程免费视频网址| 成人网站免费看黄A站视频| 无码永久免费AV网站| 久久WWW免费人成人片| 日本特黄特色aa大片免费| 亚洲欧洲国产精品你懂的| 亚洲国产精品久久久久秋霞小| 国产精品自拍亚洲| 亚洲一区在线免费观看| 精品国产呦系列在线观看免费 | 久久亚洲欧美国产精品| a级片免费在线播放| 免费日本黄色网址| 亚洲人成无码网WWW| 亚洲成av人片在线天堂无| 久久aa毛片免费播放嗯啊| 欧洲精品免费一区二区三区 | 亚洲三级高清免费| 亚洲a∨国产av综合av下载| 免费看黄的成人APP| 亚洲区不卡顿区在线观看| 亚洲人成人网站在线观看| 亚洲性色AV日韩在线观看| 亚洲第一se情网站| 国产免费拔擦拔擦8x| 亚洲国产精品无码第一区二区三区| 久久精品无码专区免费青青| 久久亚洲精品无码|