<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 閱讀(210) 評論(0)  編輯  收藏 所屬分類: Test-Driven Development

    主站蜘蛛池模板: 99亚洲男女激情在线观看| 在线aⅴ亚洲中文字幕| 人禽伦免费交视频播放| 夫妻免费无码V看片| 亚洲一区二区三区国产精华液| 2019中文字幕在线电影免费| 亚洲午夜精品在线| 免费一级不卡毛片| 中文字幕在线免费| 久久精品国产亚洲AV无码娇色| 少妇人妻偷人精品免费视频| 亚洲色图黄色小说| 国产高清免费视频| 亚洲欧美日韩中文无线码| 免费黄色网址入口| 黄色网页在线免费观看| 亚洲av永久无码精品网站| 久久久久久精品免费看SSS| 亚洲免费中文字幕| 国产成人精品免费视频大全五级| 理论秋霞在线看免费| 亚洲精品亚洲人成人网| 精品无码国产污污污免费网站| 亚洲一级视频在线观看| 国产在线不卡免费播放| 18禁在线无遮挡免费观看网站| 久久精品九九亚洲精品| 免费黄色app网站| 怡红院免费的全部视频| 亚洲av无码电影网| 四虎亚洲国产成人久久精品 | 亚洲午夜精品久久久久久浪潮 | 国产精品免费视频网站| 久久久久久久久久久免费精品 | 亚洲成AV人在线观看天堂无码| 69视频在线观看免费| 亚洲成a人片在线不卡一二三区| 国产成人精品曰本亚洲79ren| 蜜臀AV免费一区二区三区| 校园亚洲春色另类小说合集| 亚洲Av熟妇高潮30p|