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

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

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

    隨筆 - 3, 文章 - 152, 評論 - 17, 引用 - 0
    數據加載中……

    TDD(3) --轉自http://m.tkk7.com/yandazhi

    意圖編程

    programming by intention

    名字

    Use nouns or noun phrases for class names

    public class Movie {
      
    //
    }

    public class MovieRatingComparator implements Comparator {
      
    //
    }

    public class XMLMovieListReader implements MovieListReader {
      
    //
    }

    Use either adjectives or generic nouns and noun phrases for interfaces

    public interface Serializable {
    }

    public interface MovieListWriter {
      
    void write(MovieList movieList) throws IOException;
    }

    Use verbs and verb phrases for method names


    private int calculateAverageRating() {
      
    int totalRating = calculateTotalRating();
      
    return totalRating / ratings.size();
    }


    Use accepted conventions for accessors and mutators

    public Category getCategory() {
      
    return category;
    }

    public void setCategory(Category aCategory) {
      category 
    = aCategory;
    }

    public boolean isOfCategory(Category aCategory) {
      
    return category.equals(aCategory);
    }

    public boolean isRated() {
      
    return !ratings.isEmpty();
    }

    public boolean hasRating() {
      
    return !ratings.isEmpty();
    }

    public int size() {
      
    return movies.size();
    }


    Don't put redundant information in method names

    public void add(Movie movieToAdd) throws DuplicateMovieException {
      
    if (this.contains(movieToAdd)) {
        
    throw new DuplicateMovieException(movieToAdd.getName());
      }
      movies.add(movieToAdd);
    }

    There are always exceptions. Sometimes it is just clearer, and reads better, if you have type information in the method name.

    public void addRating(Rating ratingToAdd) {
      ratings.add(ratingToAdd);
    }

    Use nouns and noun phrases for variable names.

    public class Movie {
      
    private String name = "";
      
    private Category category = Category.UNCATEGORIZED;
      
    private List ratings = null;

      
    //
    }


    如何意圖編程

    包括使用隱喻,測試優先,重構,作出假定,讓編譯器告訴你下一步做什么 這幾種技巧。

    公用詞匯表 幫助你理解這個領域。
                          幫助你取名字。


    "NO COMMENT"

    Incomplete code

    // TODO: The tree should be balanced after doing the insertion.
    
    // CODE DEBT: the looping structure is a bit convoluted, could use
    // some method extraction.
    


    Refactoring doesn't make it clear enough

    // NEEDS WORK: I tried extract method, but it's still awkward.
    // Maybe refactoring to a Strategy would clean it up?
    


    Use of an unusual algorithm

    // I used an AVL Tree algorithm here to keep the tree balanced.
    


    Use of a published algorithm

    // This AVL alorithm was based on Brad Appleton's implementation at
    // http://www.enteract.com/~bradapp/ftp/src/libs/C++/AvlTrees.html
    


    Performance tuning

    // A circular queue is used here for performance reasons: to avoid
    // having to move elements around.
    


    Class comment

    /**
     * This class represents a single movie title. It is responsible for
     * maintaining its own ratings, reviews, etc.
     */
    

    posted on 2005-07-25 12:28 閱讀(216) 評論(0)  編輯  收藏 所屬分類: Test-Driven Development

    主站蜘蛛池模板: 伊人久久综在合线亚洲91| 免费国产a国产片高清网站| 亚洲色精品vr一区二区三区| 国产天堂亚洲精品| 在线观看亚洲免费视频| 亚洲精品色播一区二区 | 色窝窝亚洲AV网在线观看| 青娱分类视频精品免费2| 亚洲大片免费观看| 每天更新的免费av片在线观看 | www亚洲一级视频com| 美女视频黄频a免费| 国产高清在线精品免费软件| 亚洲αⅴ无码乱码在线观看性色 | 一级毛片aa高清免费观看| 亚洲国产专区一区| 在线看片免费人成视频久网下载| 国产91精品一区二区麻豆亚洲| 巨胸喷奶水视频www免费视频| 亚洲啪啪AV无码片| 在线观看的免费网站无遮挡| 亚洲日韩乱码中文无码蜜桃| 岛国片在线免费观看| 国产亚洲综合精品一区二区三区| 亚洲国产一成久久精品国产成人综合 | 亚洲日本一区二区| 曰曰鲁夜夜免费播放视频 | 亚洲日韩在线第一页| 国产无遮挡又黄又爽免费网站| 亚洲精品高清久久| 国内免费高清在线观看| 国产成人亚洲毛片| 久久亚洲国产中v天仙www| 久久福利资源网站免费看| 亚洲精华国产精华精华液好用| 亚洲人成无码www久久久| 一个人免费日韩不卡视频| 亚洲色无码国产精品网站可下载| 亚洲第一黄片大全| 97在线视频免费播放| 亚洲欧美成人综合久久久|