隨筆 - 3, 文章 - 152, 評論 - 17, 引用 - 0

          導(dǎo)航

          公告

          歡迎來到辰的blog

          發(fā)消息給我有事您Q我

          常用鏈接

          文章分類(153)

          搜索

          •  

          積分與排名

          • 積分 - 53313
          • 排名 - 950

          最新評論

          閱讀排行榜

          TDD(3) --轉(zhuǎn)自http://www.aygfsteel.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;

            
          //
          }


          如何意圖編程

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

          公用詞匯表 幫助你理解這個領(lǐng)域。
                                幫助你取名字。


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

          主站蜘蛛池模板: 建德市| 集贤县| 新邵县| 墨竹工卡县| 舒兰市| 河池市| 清河县| 枞阳县| 阳西县| 成都市| 永平县| 延长县| 花莲县| 合作市| 顺义区| 达日县| 略阳县| 通江县| 芦溪县| 柳林县| 日喀则市| 盐边县| 额尔古纳市| 汉沽区| 涟源市| 平遥县| 临沧市| 遂川县| 稻城县| 五寨县| 新密市| 兰州市| 罗源县| 全州县| 鄯善县| 若羌县| 图木舒克市| 新郑市| 临澧县| 成武县| 青神县|